我必须定义一个仅接受整数的输入文本。
我尝试使用正则表达式,但值的小数部分仍然可见。
我使用了这个功能:
$(document).on("input","input", function(e) {
this.value = this.value.replace(/[^\d\\-]/g,'');
})
最佳答案
这个怎么样?
$('input').on('input blur paste', function(){
$(this).val($(this).val().replace(/\D/g, ''))
})
<input>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
关于javascript - 使用 jQuery 设置输入字段仅接受数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40256685/