특정 div 또는 텍스트를 클릭 할 때 유효성을 검사 할 필드를 추가하고 싶습니다. 다음은 시나리오입니다. jQuery 유효성 검사를 사용하여 유효성이 검사 된 양식이 있습니다. 사용자가 "암호 변경"을 클릭 할 때 유효성을 검사하기 위해 유효성 검사에 포함하지 않은 두 필드가 있습니다. 본문. 런타임 중에 유효성을 검사 할 필드를 추가하고 추가 할 수 있습니까?jQuery 유효성 검사, div 클릭시 유효성 검사를위한 추가 필드 추가
<span class="change-password">Change Password</span>
$(document).ready(function() {
$("#update_user").validate({
rules: {
"admin_account[name]": {
required: true
},
"admin_account[email]": {
required: true
},
"admin_account[gender]":{
required: true
},
"admin_account[nationality]":{
required: true
},
"admin_account[photo]":{
accept: false
},
"admin_account[date_of_birth(1i)]":{
required: true
},
"admin_account[date_of_birth(2i)]":{
required: true
},
"admin_account[date_of_birth(3i)]":{
required: true
}
},
errorPlacement: function(){
return false; // suppresses error message text
}
});
//I want to trigger here an additional validation for the password field
$(".change-password").on("click", function(){
$("#update_user").validate({
rules: {
"admin_account[name]": {
required: true
},
"admin_account[email]": {
required: true
},
"admin_account[password]":{
required: true
},
"admin_account[password_confirmation]":{
required: true,
equalTo:"#edit_registerPassword"
},
"admin_account[gender]":{
required: true
},
"admin_account[nationality]":{
required: true
},
"admin_account[photo]":{
accept: false
},
"admin_account[date_of_birth(1i)]":{
required: true
},
"admin_account[date_of_birth(2i)]":{
required: true
},
"admin_account[date_of_birth(3i)]":{
required: true
}
},
errorPlacement: function(){
return false; // suppresses error message text
}
});
});
사용자가'.change-password' 요소를 클릭하면 정확히 무슨 일이 발생합니까? – undefined
암호 필드와 암호를 확인하기 위해 두 개의 필드가 표시됩니다. 나는이 두 필드가 검증되기를 원한다. 사용자가 "취소"를 클릭하면 두 필드가 숨겨지고 더 이상 유효성이 확인되지 않습니다. – user3122063