【发布时间】:2010-04-10 17:42:23
【问题描述】:
问候,
我正在使用 jquery 插件/验证库。我想允许在提交时进行验证,但我不确定应该在哪里插入代码: 我知道我可以为此使用 submitHandler,但在阅读了文档后我很难实现它,所以我需要你们的帮助。
jquery 验证工作正常,但即使输入无效,表单仍然提交的问题。
这是我的验证功能,如果输入无效,我想知道如何使它不提交表单。
顺便说一句,我正在使用 asp.net 按钮提交表单。
这是我的代码:
$(document).ready(function() {
$("#aspnetForm").validate({
rules: {
"<%=txtHomePhone.UniqueID %>": {
phonehome: true
},
"<%=txtMobileHome.UniqueID %>": {
mobilephone: true
},
"<%=txtFaxHome.UniqueID %>": {
faxhome: true
},
"<%=txtEmailHome.UniqueID %>": {
email: true
},
"<%=txtZipCodeHome.UniqueID %>": {
ziphome: true
},
//work
"<%=txtPhonework.UniqueID %>": {
phonework: true
},
"<%=txtMobileWork.UniqueID %>": {
mobilework: true
},
"<%=txtFaxWork.UniqueID %>": {
faxwork: true
},
"<%=txtEmailWork.UniqueID %>": {
email: true
},
"<%=txtWebSite.UniqueID %>": {
url: true
},
"<%=txtZipWork.UniqueID %>": {
zipwork: true
}
},
errorElement: "mydiv",
wrapper: "mydiv", // a wrapper around the error message
errorPlacement: function(error, element) {
offset = element.offset();
error.insertBefore(element)
error.addClass('message'); // add a class to the wrapper
error.css('position', 'absolute');
error.css('left', offset.left + element.outerWidth());
error.css('top', offset.top - (element.height() / 2));
}
});
【问题讨论】: