c# - CheckBox All only works first two times -


i put checkbox 'check all', , code works first check , uncheked. after none of checked box follows attribute of checkbox of 'check all'

<script type="text/javascript">     $(function () {           $('#chkall').click(function () {             $('#divchk .chk input:checkbox').attr('checked', function () {                 return $('#chkall').prop('checked');             });         });     }); </script>   <body>     <form id="form1" runat="server">         <div class="bigdiv">             <asp:checkbox id="chkall" runat="server" text="check all" /><br />             <div id="divchk">                 <asp:checkbox id="checkbox1" runat="server" text="1" cssclass="chk" /><br />                 <asp:checkbox id="checkbox2" runat="server" text="2" cssclass="chk" /><br />                 <asp:checkbox id="checkbox3" runat="server" text="3" cssclass="chk" /><br />                 <asp:checkbox id="checkbox4" runat="server" text="4" cssclass="chk" /><br />             </div>         </div>     </form> </body> 

try , see if works.

   $('#chkall').change(function () {             $('#divchk input:checkbox').prop('checked',this.checked);     }); 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -