点击任何3个“chkmain”单选按钮,应启用“child”和“child1”

时间:2011-02-07 11:24:08

标签: jquery

<input type="radio" id="chkMain" name="chkMain"/>
<input type="radio" id="chkMain1" name="chkMain" />
<input type="radio" id="chkMain2" name="chkMain" />

<input class="child" type="checkbox" id="chk1" disabled="true" />
<input class="child" type="checkbox" id="chk2" disabled="true" />
<input class="child" type="checkbox" id="chk3" disabled="true" />
<input class="child" type="checkbox" id="chk4" disabled="true" />
<input class="child" type="checkbox" id="chk5" disabled="true" />
<input class="child" type="checkbox" id="chk6" disabled="true" />
<input class="child" type="checkbox" id="chk7" disabled="true" />

<input class="child1" type="radio" id="tone1" disabled="true"/>
<input class="child1" type="radio" id="tone2" disabled="true"/>
<input class="child1" type="radio" id="tone3" disabled="true"/>


$(function()
  {
   $("input[id^='chkMain']").onclick(function() {
      //var otherCks = $("input[id^='chkMain']").not(this);
           if ($(this).is(":checked")) {
            $(".child").attr("disabled", true);
            otherCks.removeAttr("disabled");
        } else {
            $(".child").removeAttr("disabled");
            otherCks.attr("disabled", true)
        }
    });
    $("#chk_all").click(function() {
        var checked_status = this.checked;
        $("input[id^=chk]").each(function () {
            this.checked = checked_status;
        });
    });
});

1 个答案:

答案 0 :(得分:1)

这样的东西
$(function(){
    $("input:radio[name='chkMain']").change(function(){
        if (this.checked) {
            $("input:checkbox.child, input:radio.child1").removeAttr("disabled");
        }
        else {
            $("input:checkbox.child, input:radio.child1").attr("disabled", "disabled");
        }
    });
});