提交form前使用JS先進行驗證
阿新 • • 發佈:2018-03-14
this script BE his === false als onkeyup lac
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>
提交form前使用JS先進行驗證