我的 Jquery 验证器 ( http://bassistance.de/jquery-plugins/ ) 插件 submitHandler 函数有问题。表单验证正确,无效处理程序消息正确触发,但 submitHandler 函数不会正确触发,ajaxSubmit 函数也不会正确触发。有人看到我做错了什么吗?任何帮助都会受到欢迎。
<script type="text/javascript">
$(document).ready(function() {
var submitMessage = $('#submit-message'),
messageContainer = submitMessage.find('span'),
loading = $('#loading');
function showSuccess(message) {
messageContainer.text(message)
messageContainer.attr('class', 'success');
}
function showFailure(message) {
messageContainer.text(message)
messageContainer.attr('class', 'failure');
}
$("#contact-form-info").validate({
rules: {
contact_Name: {
minlength: 2,
maxlength: 50,
required: true
},
contact_Foretag: {
minlength: 1,
maxlength: 50
},
contact_Email: {
required: true,
email: true
},
contact_Subject: {
required: true,
minlength: 5,
maxlength: 50
},
contact_Message: {
required: true,
minlength: 10,
maxlength: 5000
}
},
submitHandler: function(form) {
var options = {
beforeSubmit: function() {
loading.show();
},
success: function() {
showSuccess('Thank you! Your email has been submitted.');
form.reset();
loading.hide();
},
error: function() {
showFailure("We're sorry, your email could not be sent. Please try again later.");
loading.hide();
}
};
$(form).ajaxSubmit(options);
return false;
},
invalidHandler: function() {
showFailure('There were some problems with your submission.');
}
});
});
</script>
这是我在 jsFiddle 中的代码。http://jsfiddle.net/JwNmK/