2011-11-06 17 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

関連する問題