Asp.net使用jQuery启用/禁用checkboxList

时间:2015-09-25 08:59:32

标签: javascript c# jquery asp.net

我有这种结构:

收音机按钮:

o启用o禁用

复选框

[] checkBox1

[] checkBox2

[] checkBox3

[] checkBox4

以上控件是动态生成的。

case 21:

我想要的是:当用户点击RadioButton 启用时,所有复选框都会启用,否则会禁用。

我正处于可以看到用户点击启用单选按钮的位置。

<asp:RadioButtonList runat="server" ID="rbSubsidiaries" onclick = "Radio_Click()"/>

 <asp:CheckBoxList runat="server" ID="cblSubsidiaries" Enabled="False"/>

但我不知道如何启用所有 checkBoxes

包含CheckBoxList的渲染结构的图片。前两个复选框。 https://github.com/quickfix/quickfix/blob/master/src/C%2B%2B/FieldConvertors.h#L564

4 个答案:

答案 0 :(得分:2)

尝试这样的事情:

$("#cblSubsidiaries > input[type='checkbox']").prop("disabled", false)

更新

$("#contentpage_0_content_0_cblSubsidiaries input[type=checkbox]").prop("disabled",false)

答案 1 :(得分:2)

这是可以帮助您的代码

<强> HTML

<input type="radio" name="check" value="enable" class="enableList">Enable
    <input type="radio" name="check" value="disable" class="disableList">Disable    

<div class="container">
 <input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
 <input type="checkbox" name="vehicle" value="Car">I have a car </div>

<强>脚本

$(document).ready(function () {           
        $('.enableList').change(function () {
            if ($(this).prop('checked') == true) {
                $('.container').find('input:checkbox').each(function () {
                    alert ("enable check box");
                });
            }
        });


        $('.disableList').change(function () {
            if ($(this).prop('checked') == true) {
                $('.container').find('input:checkbox').each(function () {
                    alert("disable check box");
                });
            }
        });

    });

这是工作的fidler https://jsfiddle.net/Ln7y6v0n/

答案 2 :(得分:0)

这样的事情应该有效:

$('#contentpage_0_content_0_cblSubsidiaries input[type=checkbox]').each(function() {
      $(this).prop('checked', true);
 });

答案 3 :(得分:0)

 $(document).ready(function () {

            $('#<%=RadioButtonList1.ClientID%>').change(function () {
                 $('#<%=RadioButtonList1.ClientID%>').each(function () {
                     var checked = $(this).find('input:radio:checked');
                     if (checked.val() == "Enable") {

                         $('#<%=CheckBoxList1.ClientID%>').each(function () {
                             var checked = $(this).find('input:checkbox');
                             checked.prop('checked', true);
                         });
                     }
                     else {

                         $('#<%=CheckBoxList1.ClientID%>').each(function () {
                             var checked = $(this).find('input:checkbox');
                             checked.prop('checked', false);
                         });
                     }
                 });
             });
        });

 protected void Page_Load(object sender, EventArgs e)
        {
            ListItem item = new ListItem();
            item.Text = "Enable";
            item.Value = "Enable";
            RadioButtonList1.Items.Add(item);

            ListItem item1 = new ListItem();
            item1.Text = "Disable";
            item1.Value = "Disable";
            RadioButtonList1.Items.Add(item1);

            for (int i = 1; i <= 4; i++)
            {
                ListItem chkitem = new ListItem();
                chkitem.Text = "Checkbox" + i;
                chkitem.Value = "Checkbox" + i;
                CheckBoxList1.Items.Add(chkitem);
            }

        }

 <div>
            <asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
            <br />
            <hr />
            <asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
        </div>