html代码
<form id="myForm" method="post" action="" onsubmit="return check()"> <input id="num" type="number" onkeyup="this.value=this.value.replace(/D/g,'')" onafterpaste="this.value=this.value.replace(/D/g,'')" > <input type="submit" id="submit" value="提交"> </form>
JS代码
<script> function check() { var num= document.getElementById("num").value; if (num== null || num === '') { alert("请填写数字"); return false; } return true; } </script>