通过javascript启用/禁用asp.net复选框

问题描述:

例如,当我选中chk1然后chk2,chk3和chk4时,通过javascript启用和禁用复选框.如果我取消选中chk1,则通过javascript禁用chk2,chk3和chk4?

Enabling and disabling checkboxes through javascript for example when I check chk1 and then chk2, chk3 and chk4 will be enabled and if I uncheck chk1 then chk2, chk3 and chk4 will be disabled through javascript?

这是我的代码:

<script type="text/javascript">
$('chkTAR').clicked(function(){
        {
        if($('chkTAR :checked').length == 2)

        $('chkOasis, chkPOT').disabled = true;
        else
        $('chkOasis, chkPOT').disabled = false
        });
</script>

您可以尝试以下操作:

   <script language="javascript" type="text/javascript">

       function oncheckchange(checked) { 
           var chk2 = document.getElementById('chk2'); 
           chk2.disabled = checked;  
       }
   </script>

  <asp:CheckBox OnClick="oncheckchange(this.checked);"  ID="chk1" runat="server" />
  <asp:CheckBox ID="chk2" runat="server" ClientIDMode="Static" />

请注意,chk2的ClientIDMode设置为静态".

Note that chk2's ClientIDMode is set to "Static".