JS怎么实现只能输入js字符串数字与数字相加和*号组合?

1.HTML5对于ie10以下浏览器,此处并不好使。不支持HTML5。
第一种
<input type="number" />
第二种
<input type="text" pattern=[0-9] />但是在IE兼容模式下并不生效。2. 使用JavaScript<input type="text" name="number" id="filter">function clearNoNumber(_this){
var result = $(_this).val().replace(/\D/g,'');
$(_this).val(result);
}
$('#filter').on('focus',function () {
clearNoNumber(this);
});
$('#filter').on('keyup',function () {
clearNoNumber(this);
});
$('#filter').on('blur',function () {
clearNoNumber(this);
})亲测IE兼容模式下仍然有效,非数字无法显示在文本框中。

我要回帖

更多关于 js字符串数字与数字相加 的文章

 

随机推荐