使用第一个复选框启用电台列表

时间:2014-03-01 05:21:19

标签: javascript php

列出的收音机已禁用,现在我想在选中复选框时启用它们,并在取消选中时禁用。

 <p>1.0 Educational Qualification</p>
 <p><input type="checkbox" id="chk" name="chk"/>1.1 Highest relevant academic degree or educational attainment</p>
 <p><input type="radio" name="educationalqualification" disabled="true"/>Doctorate</p>
 <p><input type="radio" name="educationalqualification" disabled="true"/>Master's Degree</p>
 <p><input type="radio" name="educationalqualification" disabled="true"/>LLB and MD</p>
 <p><input type="radio" name="educationalqualification" disabled="true"/>Diploma Course (Above Bachelor's Degree)</p>
 <p><input type="radio" name="educationalqualification" disabled="true"/>Bachelor's Degree</p>

</body>

3 个答案:

答案 0 :(得分:1)

试试这个

 <script>
 $(document).ready(function(){
    $("input[type='checkbox']").click(function(){
        if($(this).is(":checked"))
        {
            $("input[type='radio']").prop("disabled",false);
        }
        else
        {
            $("input[type='radio']").prop("disabled",true);
                    $("input[type='radio']").prop("checked",false);
        }
    });
 });
 </script>

参见 FIDDLE DEMO

答案 1 :(得分:1)

试试这个:

 $(document).ready(function(){
       $('#chk').click(function () {
           if($(this).prop('checked')){
             $('input[name=educationalqualification]').attr("disabled",false);
           }
           else {
             $('input[name=educationalqualification]').attr("disabled",true);  
           }
    });
  });

demo

答案 2 :(得分:1)

和香草:

function toggle(checked) {
    var names = document.getElementsByName("educationalqualification");

    for (var i = 0; i <= names.length - 1; i++) {
        names[i].disabled = !checked;
        names[i].checked = false;
    }
}

var check = document.getElementById("chk");
check.addEventListener("click", function () {
    toggle(this.checked)
});

<强> JSFiddle