使用JS和JQuery 阻止表单提交的两种方法

mac2022-06-30  85

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> <title>JavaScript禁止提交表单</title> <script type="text/javascript"> function getObj(id){ var Obj = document.getElementById(id).value; return Obj; } function check(){ if(getObj("test")==""){ alert("文本框输入为空,不能提交表单!"); document.getElementById("test").focus; return false;//false:阻止提交表单 } } </script> </head> <body> <form action="index.htm" method="post" οnsubmit="return check()"> <input type="text" name="test" id="test"> <input type="submit" value="提交"> </form> </body> </html>

转载于:https://www.cnblogs.com/hgj123/p/5816858.html

最新回复(0)