Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

Select all checkboxes using Javascript or jQuery

I want to check/uncheck all check boxes of a particular row in a table if Select all Checkbox is selected for that particular row

Here is the html for a single row.

<tr>
    <td class="left">
        <label>Admin - Organization</label>
    </td>

    <td>
        <div class="checkbox">
        <label><asp:CheckBox cssclass="selectallAO" runat="server" /></label>
        </div>
    </td>
    <td>
        <div class="checkbox">
        <label><asp:CheckBox cssclass="checkboxAO" ID="chkbxViewAOrganization" runat="server" /></label>
        </div>
    </td>
    <td>
        <div class="checkbox">
        <label><asp:CheckBox cssclass="checkboxAO" ID="chkbxAddAOrganization" runat="server" /></label>
        </div>
    </td>
    <td>
        <div class="checkbox">
        <label><asp:CheckBox cssclass="checkboxAO" ID="chkbxEditAOrganization" runat="server" /></label>
        </div>
    </td>
    <td>
        <div class="checkbox">
        <label><asp:CheckBox cssclass="checkboxAO" ID="chkbxDeleteAOrganization" runat="server" /></label>
        </div>
    </td>                                
</tr>

There are 5 other rows like this for other pages as well. So, I want to check/uncheck all checkbox's for a particular row for which Select All was checked/unchecked.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

UPDATE

Updated the jQuery function to make the master checkbox override child checkbox states.


How does something like this sound? I wasn't sure which classes were your checkboxes so you'll have to tweak this a bit:

HTML:

<div class="spacer"><input type="checkbox" class="selectallAO"> Select All</div>
<div class="spacer"><input type="checkbox" class="checkboxAO"> Regular</div>
<div class="spacer"><input type="checkbox" class="checkboxAO"> Regular</div>

CSS:

div.spacer {
    display: block;
}

JS:

$('.selectallAO').click(function() {
    this.checked ? $('.checkboxAO').prop('checked', true) : $('.checkboxAO').prop('checked', false);
});

jsFiddle


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...