1

Validation Plug-in の「required (dependency-expression)」の説明からこの例を使用します。

$("#myform").validate({
  rules: {
    details: {
      required: "#other:checked"
    }
  }, debug:true
});
$("#other").click(function() {
    $("#details").valid();
});

以下の例でラジオボタン #guide が選択されている場合、テキスト入力を必須にしようとしています:

<input type="radio" id="outfitter" name="memtype" value="Outfitter" />Outfitter $125
<input type="radio" id="guide" name="memtype" value="Guide" />Guide $75
<input type="text" id="sponout" name="sponout" size="75" />

どこに置けばいいのかわからない

 $("#other").click(function() {
    $("#details").valid();
 });

ルール検証コーディング内。

4

1 に答える 1

2

これを行う方法の 1 つを次に示します。

$("#myform").validate({
    rules: {
        sponout: {
            required: "#guide:checked"
        }
    }
});

$("input[name='memtype']").change(function () {
    $("#myform").valid();
});

例: http://jsfiddle.net/kqczf/1/

于 2012-10-04T00:34:51.627 に答える