点击id = checkMain我希望“child”(复选框)启用,“child1”(单选按钮)被禁用

时间:2011-02-07 15:30:52

标签: 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:radio[id=checkMain]").click(function(){
        if (this.checked) {
            $("input:checkbox.child").removeAttr("disabled");
        }
        else {
             $("input:checkbox.child, input:radio.child1").attr("disabled", "enabled");

        }
    });
});

1 个答案:

答案 0 :(得分:0)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('.child, .child1').attr('disabled', true);

            $('.Enable:radio').live('click', function () {
                $('.child').attr('disabled', !$(this).hasClass('CheckBox'));
                $('.child1').attr('disabled', !$(this).hasClass('Radio'));
            });
        });
    </script>
</head>
<body>
    <input type="radio" id="chkMain" name="chkMain" class="Enable CheckBox" />
    Enable Checkbox List And Disable Radio Button List<br />
    <input type="radio" id="chkMain1" name="chkMain" class="Enable CheckBox Radio" />
    Enable Checkbox List And Radio Button List<br />
    <input type="radio" id="chkMain2" name="chkMain" class="Enable Radio" />
    Disable Checkbox List And Disable Radio Button List<br />
    <br />
    <br />
    <br />
    <input class="child" type="checkbox" id="chk1" />1<br />
    <input class="child" type="checkbox" id="chk2" />2<br />
    <input class="child" type="checkbox" id="chk3" />3<br />
    <input class="child" type="checkbox" id="chk4" />4<br />
    <input class="child" type="checkbox" id="chk5" />5<br />
    <input class="child" type="checkbox" id="chk6" />6<br />
    <input class="child" type="checkbox" id="chk7" />7<br />
    <br />
    <br />
    <br />
    <input class="child1" type="radio" id="tone1" />1<br />
    <input class="child1" type="radio" id="tone2" />2<br />
    <input class="child1" type="radio" id="tone3" />3<br />
</body>
</html>