我有以下网格视图 -
<asp:GridView ID="group_table" Runat="server"
AutoGenerateColumns="False" onprerender="group_table_PreRender"
onrowdatabound="group_table_RowDataBound"
ClientIDMode="Static" CellPadding="4" ForeColor="#333333"
GridLines="None" Width="915px" BorderStyle=Ridge >
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField ItemStyle-Width=90>
<HeaderTemplate>
<asp:CheckBox ID="selectAllCheckBox" runat="server" Text="Select all"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="selectCheckBox" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
并尝试实现以下 javascript 函数,以便当用户单击selectAllCheckBox
所有复选框时将被选中 -
$(document).ready(function() {
var headerCheckbox = $('#group_table > tbody > tr > th > input:checkbox');
headerCheckbox.click(function() {
var headerChecked = $(this).attr('checked');
var rowCheckboxes = $('#group_table > tbody > tr > td > input:checkbox');
rowCheckboxes.attr('checked', headerChecked);
});
});
但由于某种原因,这没有影响,我哪里错了?