在input标签中添加
onkeyup="this.value=this.value.replace(/[^\d]/g,'')"
r1= /^[A-Za-z]+$/,//大小写的英文
r2=/^[0-9]+$/,///数字
r3=/^[\u4e00-\u9fa5]+$/,//汉字
r4=/^[A-Za-z0-9\u4e00-\u9fa5]+$/,//数字、英文和汉子
本文介绍了一种在HTML输入框中仅允许输入数字的方法,通过使用onkeyup事件和正则表达式实现对非数字字符的过滤。
在input标签中添加
onkeyup="this.value=this.value.replace(/[^\d]/g,'')"
r1= /^[A-Za-z]+$/,//大小写的英文
r2=/^[0-9]+$/,///数字
r3=/^[\u4e00-\u9fa5]+$/,//汉字
r4=/^[A-Za-z0-9\u4e00-\u9fa5]+$/,//数字、英文和汉子
转载于:https://www.cnblogs.com/chenlongsheng/p/11132148.html
388

被折叠的 条评论
为什么被折叠?