INPUT只能輸入數字


input只能輸入數字:

(只能輸入數字,並且輸入的值不能大於99),但是這樣有個問題,就是當輸入非數字字符時,輸入框中所有的字符都會被清除

<input type="text" id="feePercentage" name="feePercentage" value="" 
onkeyup
="if(isNaN(value) || value > 99)execCommand('undo')" onafterpaste="if(isNaN(value) || value > 99)execCommand('undo')" style="margin-left:0px; width:50px;" onchange="calc()"/>

 

解決方案:

(只清除非數字,原先的數字保留)

<input class="text" id="policyNo" name="policyNo" type="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" 
maxlength="14" style="width:188px;" placeHolder="請輸入批單號">


免責聲明!

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



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