JQ设置input框只能输入数字并限制个数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zyj_15067066062/article/details/80757739

<input type="text" name="CreatorName" id="CreatorName" value="" maxlength='4'>

//给input设置只能输入数字,如果是非数字会自动删掉

$("#CreatorName").keyup(function(){
    $(this).val($(this).val().replace( /[^0-9]/g,''));
}).bind("paste",function(){
    $(this).val($(this).val().replace( /[^0-9]/g,''));
})
//限制输入4个数  可以在input标签中添加 maxlength='4' 属性即可限制

猜你喜欢

转载自blog.csdn.net/zyj_15067066062/article/details/80757739