html input如何只能输入数字

原创
ithorizon 4个月前 (10-19) 阅读数 45 #HTML
input只能输入数字的方法:在input标签中使用oninput属性配合正则表达式添加输入限制事件即可,语法格式“”。

本教程操作环境:windows7系统、HTML5版、Dell G3电脑。

html input标签 要求只能输入纯数字

在input标签添加oninput = "value=value.replace(/[^\d]/g,'')"代码即可

示例:

<input type="text" oninput = "value=value.replace(/[^\d]/g,&#39;&#39;)">

效果图

立即学习“前端免费学习笔记(深入)”;

说明:

oninput 事件在用户输入时触发。

该事件在



热门