1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>js验证表单示例</title> <script> function validateForm(){ var x=document.forms["myForm"]["fname"].value; if(x==null||x==""){ alert('姓不能为空'); return false; } } </script> </head> <body> <form name="myForm" action="/statics/demosource/demo-form.php" onsubmit="return validateForm()" method="post"> 姓: <input type="text" name="fname"> <input type="submit" value="提交"> </form> </body> </html>
|