JavaScript
JavaScript 表单验证
以上函数在 form 表单提交时被调用
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <head> <script> function validateForm() { var x = document.forms["myForm"]["fname"].value; if (x == null || x == "") { alert("姓必须填写"); return false; } } </script> </head> <body> <form name="myForm" action="/plays/html-form-submit" onsubmit="return validateForm()" method="post"> 姓: <input type="text" name="fname"> <input type="submit" value="提交"> </form> </body> </html>
运行结果:
点击运行 »