所以我正在创建一个联系表单,我正在尝试创建一个验证脚本,它根本不起作用,甚至不显示错误。它只是进行默认验证。
我查看了资源,并且JS文件已加载到页面上,但是只是不起作用...?
jQuery.validator.addMethod("answercheck", function(e, t) {
return this.optional(t) || /^\bcat\b$/.test(e)
}, "Please type the correct answer"), $(function() {
$("#contact").validate({
rules: {
name: {
required: !0,
minlength: 2
},
email: {
required: !0,
email: !0
},
message: {
required: !0
},
answer: {
required: !0,
answercheck: !0
}
},
messages: {
name: {
required: "Please enter a name",
minlength: "Your name must consist of at least 2 characters"
},
email: {
required: "Please enter an email"
},
message: {
required: "Please enter a message",
minlength: "Please enter a longer message"
},
answer: {
required: "Incorrect"
}
},
submitHandler: function(form) {
$(form).ajaxSubmit({
type:"POST",
data: $(form).serialize(),
url:"process.php",
success: function() {
$('#contact :input').attr('disabled', 'disabled');
$('#contact').fadeTo( "slow", 0.15, function() {
$(this).find(':input').attr('disabled', 'disabled');
$(this).find('label').css('cursor','default');
$('#success').fadeIn();
});
},
error: function() {
$('#contact').fadeTo( "slow", 0.15, function() {
$('#error').fadeIn();
});
}
});
}
});
});
答案 0 :(得分:0)
如果您检查控制台,则会看到错误:
未捕获的TypeError:$(...)。sticky不是函数
该错误会阻止其他脚本执行和验证。
答案 1 :(得分:0)
您的问题出现在其他代码段中:
$(document).ready(function(){
$('#links').ReSmenu({
maxWidth: 750
});
$("#header2").sticky({ //<--- here is the error thrown
className: 'stuck'
});
});
在控制台(F12
)中,您可以看到错误消息:
未捕获的TypeError:$(...)。sticky不是函数