JQuery禁用form提交事件

来源:互联网 发布:linux php开发工具 编辑:程序博客网 时间:2024/05/16 05:06

在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>