文本框僅允許輸入大於0的正整數


系統有個欄位,作為參數設置,限制用戶只能輸入大於0的正整數:

 

<input type="text" name="non" ng-model="non" 
                    onpaste="return false;"
                    onkeyup="if (
                                    this.value.length == 1
                                ) {
                                    this.value = this.value.replace(/[^1-9]/g, '')
                                }
                                else {
                                    this.value = this.value.replace(/\D/g, '')
                                }"
                    onafterpaste="if (
                                    this.value.length == 1) {
                                    this.value = this.value.replace(/[^1-9]/g, '0')
                                }
                                else {
                                    this.value = this.value.replace(/\D/g, '')
                                }" />
Source Code

 

上面有一個onpaste屬性,即是說,此文本框不接受粘貼數據。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM