input属性设置type="number"之后, 仍可输入e;input限制只输入数字

1.解决方法一(中文状态下e还可以输入):
onkeypress='return( /[d]/.test(String.fromCharCode(event.keyCode) ) )'
 
2.基于1方法中的弊端,我用了下面的解决办法:
 
只需在行内输入   onKeyUp="this.value=this.value.replace(/[^.d]/g,'');"     就解决了
 
<input type="text"  onKeyUp="this.value=this.value.replace(/[^.d]/g,'');" >
注:type="number"的话火狐下不能输入小数
原文地址:https://www.cnblogs.com/ting-0424/p/13151521.html