Hello guys我开始使用jquery,当我尝试通过单击另一个复选框来选择页面中的所有复选框时遇到问题。通过选择另一个复选框来选择所有复选框
这是我的jQuery代码:
$('.selecionarTodos').live('click', function() {
alert("test");
var checkbox = $(this).children('td').children('[type="checkbox"]');
$('.headerChkItem').each(function() {
if (checkbox.is(':checked')) {
$(this).css('background-color', '');
checkbox.attr('checked', false);
$(this).children('td').children('[id*="hfSelecionada"]').val('false');
qtdTotal = qtdTotal - parseFloat($(this).children('.quantidade').text().replace(',', '.'));
}
else {
$(this).css('background-color', '#e8f783');
checkbox.attr('checked', true);
$(this).children('td').children('[id*="hfSelecionada"]').val('true');
qtdTotal = qtdTotal + parseFloat($(this).children('.quantidade').text().replace(',', '.'));
}
});
});
,这是我的客户端代码:
<asp:TemplateField HeaderText="Selecionar" ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<input type="checkbox" id="headerChkItem" cssclass="selecionarTodos" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<input type="checkbox" id="chkItem" disabled="disabled" cssclass="selecionado" runat="server" />
</ItemTemplate>
</asp:TemplateField>
PS:当我测试jQuery的 “警报” 没有运行。 在此先感谢。
好的,我已经改变了cssclass,并且它已经被执行了,但是现在我仍然必须通过点击这个复选框来选择所有的itens,我必须循环所有的网格线吗? – guisantogui 2013-04-22 15:06:52
你可以在客户端发布HTML,而不是上面的服务器端代码吗?我看不到标签在哪里,等等。另外 - 你是否将ID改为一个类? – 2013-04-22 15:13:20