2015-09-25 68 views
1

我有这样的结构:Asp.net启用/禁用的CheckBoxList与jQuery

单选按钮:

o启用o禁用

复选框

[] checkBox1

[] checkBox2

[] checkBox3

[] checkBox4

,以上两种控制是动态生成的。

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

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

我要的是:当在单选按钮用户点击启用所有复选框得到允许,否则禁止。

我现在可以看到如果用户点击了启用单选按钮。

function Radio_Click() { 
if ($('#<%=rbSubsidiaries.ClientID %> input:checked').val() == 'enable') { 
      alert('enable is clicked'); 
} 
} 

但我不知道如何使所有的复选框

图片包含CheckBoxList的渲染结构。前两个复选框。 enter image description here

回答

2

尝试这样:

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

更新:

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

否其无效。仍然是相同的结果 – Kamran

+0

你可以显示CheckBoxList的呈现结构吗? – Bubavanhalen

+0

我已更新问题 – Kamran

0

像这样的东西应该工作:

$('#contentpage_0_content_0_cblSubsidiaries input[type=checkbox]').each(function() { 
     $(this).prop('checked', true); 
}); 
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>

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"); 
       }); 
      } 
     }); 

    }); 

这是工作网络dler https://jsfiddle.net/Ln7y6v0n/