1.解决方法一(中文状态下e还可以输入):
onkeypress=‘return( /[\d]/.test(String.fromCharCode(event.keyCode) ) )‘
2.基于1方法中的弊端,我用了下面的解决办法:
只需在行内输入 onKeyUp="this.value=this.value.replace(/[^\.\d]/g,‘‘);" 就解决了
<input type="number" onKeyUp="this.value=this.value.replace(/[^\.\d]/g,‘‘);" >
input属性设置type="number"之后, 仍可输入e;input限制只输入数字
原文:https://www.cnblogs.com/ting-0424/p/13151521.html