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>声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇: 2016上海某公司面试题
- 下一篇: Nginx笔记(一)----Centos7编译安装Nginx
