0
OnValid 이벤트에 대한 메서드 호출을 사용하고 있지만 내 메서드의 값을 내 메서드에서 참조하려고 할 때 내 양식의 값이 지워졌습니다. 아무도 내가 뭘 잘못하고 있는지 알아?Jquery 유효성 검사 onValid
$("form").validate({
//errorLabelContainer: $("#divErrors"),
rules: {
txtUserName: {
required: true,
minlength: 4,
maxlength: 20
},
txtPassword: {
required: true,
minlength: 4,
maxlength: 32
},
txtConfirmPassword: {
required: true,
equalTo: "#txtPassword",
minlength: 4,
maxlength: 32
},
txtFirstName: {
required: true,
maxlength: 50
},
txtLastName: {
required: true,
maxlength: 50
},
txtJobTitle: {
required: true,
maxlength: 100
},
txtEmailAddress: {
required: true,
email: true,
maxlength: 100
},
txtTelephoneNumber: {
required: true,
number: true//,
//postalCode:true
}
},
messages: {
txtUserName: {
required: "Please enter a User Name",
minlength: "User Name must be at least 4 characters",
maxlength: "User Name must be no more than 20 characters"
},
txtPassword: {
required: "Please enter a Password",
minlength: "Password must be at least 4 characters",
maxlength: "Password must be no more than 32 characters"
},
txtConfirmPassword: {
required: "Please confirm Password",
equalTo: "Confirm Password must match Password",
minlength: "Confirm Password must be at least 4 characters",
maxlength: "Confirm Password must be no more than 32 characters"
},
txtFirstName: {
required: "Please enter a First Name",
maxlength: "First Name must be no more than 50 characters"
},
txtLastName: {
required: "Please enter a Last Name",
maxlength: "Last Name must be no more than 50 characters"
},
txtJobTitle: {
required: "Please enter a Job Title",
maxlength: "Job Title must be no more than 100 characters"
},
txtEmailAddress: {
required: "Please enter an Email Address",
email: "Please enter a valid Email Address",
maxlength: "Email Address must be no more than 100 characters"
},
txtTelephoneNumber: {
required: "Please enter a Telephone Number",
number: "Telephone Number must be numeric"
}
}
onValid : function() {
addUser();
}
});
});
function addUser() {
alert($('input[name="txtUserName"]').val());
}
편집 : 당신의 도움에 대한
많은 감사합니다! submitHandler에 대한 함수를 지정할 때 메소드를 호출하여 예를 들어 추가 유효성 검증을 수행 한 후 다른 메소드를 호출하여 데이터베이스에 쓸 수 있습니까? 내 submitHandler에서 메소드를 지정했지만 'invalid label { "d": 0}'오류가 발생합니다.
$.validator.setDefaults({
submitHandler: function() { addUser(); }
});
function addUser() {
//check for unique username and email
$.ajax(
{
type: "POST",
url: "/Services/CDServices.asmx/CheckForUniqueUserName",
data: "{strUserName:'" + $('input[name="txtUserName"]').val() + "'}",
async: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function(msg) {
if (msg.d == 0) {
alert("already exists");
}
else {
alert("username is unique");
}
}
});