开发者

Select and Deselect the checkboxs using JQuery

开发者 https://www.devze.com 2023-03-05 19:38 出处:网络
I am using JQuery and I have below HTML with checkboxes in it. <div class=\"selectallitems\"> <div class=\"selectall\">

I am using JQuery and I have below HTML with checkboxes in it.

 <div class="selectallitems">
                    <div class="selectall">
                        <asp:CheckBox ID="chkSelectAll"开发者_JS百科 CssClass="selectall-txt" runat="server" />
                    </div>
                    <div id="divCheckAll">
                        <div class="selectall">
                            <asp:CheckBox ID="chkItemLists" CssClass="selectall-txt-1" runat="server" />
                            <div class="clear">
                            </div>
                        </div>
                        <br />
                        <div class="selectall">
                            <asp:CheckBox ID="chkComponentLinks" CssClass="selectall-txt-1" runat="server" />
                            <div class="clear">
                            </div>
                        </div>
                        <br />
                        <div class="selectall">
                            <asp:CheckBox ID="chkResourceKeyData" CssClass="selectall-txt-1" runat="server" /></div>
                        <br />
                    </div>
                </div>

Now I want whenever user selects "chkSelectAll" then it should select all other checkboxes and whenever user deselect any of them it should deselect the "chkSelectAll".

Please suggest!!


You would basically do something like this:

$('#myCheckAllCheckbox').click(function()
{
     // Other jQuery versions:
     if(this.checked)
        $('input[@type=checkbox]').attr('checked', 'checked');
     else
        $('input[@type=checkbox]').removeAttr('checked');

     // jQuery 1.6
     $('input[@type=checkbox]').prop('checked', this.checked);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号