JQuery禁用form提交事件
在form表单中使用了button的onclick进行跳转,每次点击button时,就会引起表单的提交事件,解决方法就是在点击button的时候禁用表单提交事件:
<script type="text/javascript"> function check(){ var password = document.getElementById("password").value; var pwd = document.getElementById("pwd").value; if(password==pwd){ alert("验证正确"); document.getElementById("form1").submit(); //验证成功进行表单提交 }else{ alert("验证错误,请重新输入"); //window.location.href="index.jsp"; 可以将其连接到指定的位置 } } function add(){ $("#form1").submit(function(e){ e.preventDefault(); }); window.location.href = "index.jsp"; } </script> <form action="action" method="post" id="form1"> 用 户 名:<input type="text" name="username" id="username"> 密 码:<input type="password" name="password" id="password"> 确认密码:<input type="password" name="pwd" id="pwd"> <input type="button" onclick="add()" value="跳转"> /*这里点击跳转,没用,会刷新下页面*/ <input type="button" onclick="check()" value="提交" > </form>
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 请用fontAwesome代替网页icon小图标
- 下一篇: Linux stat函数讲解: