在input标签添加以下代码即可
oninput = "value=value.replace(/[^\d]/g,'')"
<input type="text" oninput = "value=value.replace(/[^\d]/g,'')">
oninput = "value=value.replace(/[^\d]/g,'')"
<input type="text" oninput = "value=value.replace(/[^\d]/g,'')">
转载于:https://www.cnblogs.com/xiakecp/p/11594981.html