更新时间:2023-02-21 12:26:44
试试这个:
try this :
( .numericalOnly)。keypress(function (e){
if (key === 9 ){ // 按下TAB
返回 false ;}
if ( String .fromCharCode(e.keyCode).match(/[^0-9]/g)) return false ;
}
});
(".numericOnly").keypress(function (e) { if (key === 9 ) { //TAB was pressed return false;} if (String.fromCharCode(e.keyCode).match(/[^0-9]/g)) return false; } });
<script>function checkInput(ob) {
var invalidChars = /[^0-9]/gi
if(invalidChars.test(ob.value)) {
ob.value = ob.value.replace(invalidChars,"");
}
}