こんにちは、jQuery Validation を使用しようとしています。
基本的に、私は form を持っています。ここでは、特定の要素が何があっても必要です。
しかし、チェックボックスが選択されている場合にのみ必要な他のフィールドがあります
私はjQuery Validationを使用しています ここにドキュメントへのリンクがあります
これが私のフォームです
<form action="http://www.funnytennisstories.com/save-story.php" method="POST" name="story-form" id="storyForm">
<fieldset>
    <label for="Your Story">Your Story</label>
    <textarea class="required" name="your-story" cols="" rows=""></textarea>
    <label for="free-wrist-band">Check the box to receive a free tennis wristband    </label>
    <input id="free-wrist-band-check-box" name="free-wrist-band" type="checkbox" />
    <label for="address">Address</label><input id="address" class="txtClass shipping" name="address" type="text" >
    <input type="submit" name="story-post" value="Post Your Story"/>
 </fieldset>
</form>
だから私はそれをかなり削減しましたが、基本的にfree-wrist-band-check-boxは選択されている場合は住所のテキストを入力する必要がありますが、チェックされていない場合はテキストを入力する必要はありません
ここに私が書いたJavaScriptがありますが、チェックボックスが選択されていると機能しません
<script>
 $(document).ready(function(){
    $("#storyForm").validate({
    debug:true,
       rules: {
         shipping: {
             required: $("#free-wrist-band-check-box:checked")
           }
       }
    });
});
デバッグは、chrome の firebug lite (および要素の検査ツール) と safari のインスペクターにも表示されません。
どんなアイデアでも