0
Ні, 모두!jQuery 유효성 검사 플러그인. 비 형식 필드에 대한 유효성 검사?
jQuery.Validation 플러그인에 대해 약간의 질문이 있습니다. - jQuery.Validation 플러그인을 사용하여 양식 필드가 아닌 입력 필드 (예 : '양식'태그에 없음)에 대한 유효성 검사를 완료 할 수 있습니까?
감사합니다.
Ні, 모두!jQuery 유효성 검사 플러그인. 비 형식 필드에 대한 유효성 검사?
jQuery.Validation 플러그인에 대해 약간의 질문이 있습니다. - jQuery.Validation 플러그인을 사용하여 양식 필드가 아닌 입력 필드 (예 : '양식'태그에 없음)에 대한 유효성 검사를 완료 할 수 있습니까?
감사합니다.
예, 가능하지만 필드는 여전히 <form>
태그 집합 안에 있어야합니다. 그러나 을 입력하지 않은 경우은 내부 필드의 유효성을 검사하기 위해 form
을 "제출"해야합니다. .valid()
방법을 사용하여 form
제출과 별도로이 양식을 확인하십시오.
<form id="myNonsubmitForm" action="#">
<textarea name="comments" id="comments" rows="5" cols="30"></textarea>
</form>
<button id="myButton">Click to Check Validation Status</button>
<input type="text" id="output" />
$(document).ready(function() {
$("#myNonsubmitForm").validate({
validClass: 'valid', // as per your configuration
rules: { // set rules as per your configuration
comments: {
required: false,
maxlength: 10
}
},
errorPlacement: function(error, element) {
// use this to control placement of error messages
// removal of errorPlacement handler will result in message appearing next to field automatically.
}
});
$("#myButton").click(function() { // validate on button click for this example
if($("#myNonsubmitForm").valid()){
$('#output').val('passed');
} else {
$('#output').val('failed');
};
});
});
, 왜 당신은'form' 태그를 사용할 수없는 이유는 무엇입니까? – Sparky
네 말이 맞아. 문서를 자세히 검토 한 결과, 양식을 사용할 수없는 이유는 없습니다. 감사! – ramb0tn1k