使用jquery.validate submitHandler必须点击两次才能提交表单
$(function () {
// 正常登录表单验证
$("#logForm").validate({
debug: true,
ignore: "",
errorClass: "has-error",
errorElement: "span",
errorPlacement: function (error, element) {
element.after(error.addClass("help-block"));
},
rules: {
user: 'required',
password: 'required',
},
messages: {
user: "请输入手机号/邮箱/账号",
password: "请输入密码",
},
submitHandler: function () {
//普通登录
$('#logSub').click(function () {
// console.log('submit')
if (isDrag) {
var userName = $('#user').val();
console.log(userName)
var pass = $.md5($('#password').val());
$.ajax({
type: "post",
url: "...",
crossDomain: true,
cache: false,
data: 'userName=' + userName + '&password=' + pass,
dataType: 'json',
success: function (message) {
console.log(message)
if (message.flag == 1) {
alert(message.msg)
parent.location = "./index.html"
} else if (message.flag == -1) {
alert(message.msg)
}
},
error: function (message) {
console.log(message)
console.log(XMLHttpRequest.status);
console.log(XMLHttpRequest.readyState);
}
})
} else {
alert('请滑动验证')
}
})
}
});
});
去掉点击事件$('#logSub').click(function () {}
就可以了,因为验证空间自动包含这个事件了。