gpt4 book ai didi

JQuery 验证插件强制双击才能提交​​表单

转载 作者:行者123 更新时间:2023-12-01 03:53:32 25 4
gpt4 key购买 nike

我必须单击表单上的提交按钮两次才能提交。我该如何让用户只需单击“提交”?但是,我不想启用 onfocusout 或 onkeyup。我只想通过单击提交按钮来验证我的表单。

    $(document).ready(function() {
$.validator.setDefaults({
onfocusout: false,
onkeyup: false
});

$.validator.addMethod("username", function(value, element) {
return this.optional(element) || /^[a-z]+$/i.test(value);
}, "Your username may only contain letters");

var validator = $("#registerForm").validate({
showErrors: function(errorMap, errorList) {
$("#registerForm").find("input").each(function() {
$(this).removeClass("error");
});
$("#errorcontainer").html("");
if(errorList.length) {
$("#errorcontainer").html(errorList[0]['message']);
$(errorList[0]['element']).addClass("error");
$('#errorcontainer').css('display','none');
$('#errorcontainer').fadeIn(400);
}
else {
$('#errorcontainer').css('display','none');
}
},

rules: {
username: {
required: true,
rangelength: [3,15],
remote: "usernamevalidation.php"
},
password: {
required: true,
rangelength: [5,20]
},
passwordconfirm: {
required: true,
equalTo: "#password"
},
email: {
required: true,
email: true,
remote: "emailvalidation.php"
}
},

messages: {
username: {
required: "You must enter a username.",
rangelength: "Your username must be between {0} and {1} letters.",
remote: "Your desired username is already in use."
},
password: {
required: "You must enter a password.",
rangelength: "Your password must be between {0} and {1} letters."
},
passwordconfirm: {
required: "Your passwords must match.",
equalTo: "Your passwords must match."
},
email: {
required: "You must enter an email address.",
email: "Your email address is not valid.",
remote: "This email is already in use."
}
}
});
});

最佳答案

嗨,我使用了 jquery validate 附带的 shubmitHandler

submitHandler: 函数(表单) {
表单.提交();
返回错误
});

希望对你有帮助

关于JQuery 验证插件强制双击才能提交​​表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5285946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com