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

时间:2020-06-17 13:21:02   收藏:0   阅读:123
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,‘‘);" >

原文:https://www.cnblogs.com/ting-0424/p/13151521.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!