2011-11-06 9 views

답변

1

예, 가능하지만 필드는 여전히 <form> 태그 집합 안에 있어야합니다. 그러나 을 입력하지 않은 경우은 내부 필드의 유효성을 검사하기 위해 form을 "제출"해야합니다. .valid() 방법을 사용하여 form 제출과 별도로이 양식을 확인하십시오.

http://jsfiddle.net/9fgVN/13/

ramb0tn1k @
<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'); 
     }; 
    }); 

}); 
+0

, 왜 당신은'form' 태그를 사용할 수없는 이유는 무엇입니까? – Sparky

+0

네 말이 맞아. 문서를 자세히 검토 한 결과, 양식을 사용할 수없는 이유는 없습니다. 감사! – ramb0tn1k

관련 문제