[英]JQuery Check All/ Uncheck All not working on ASP.NET
$(document).ready(function() {
$('#chkRFI').click(
function() {
$("INPUT[type='checkbox']").attr('checked', $('#chkRFI').is(':checked'));
}); });
<div class="grid_3">
<div class="box">
<div class="boxheader">
<asp:CheckBox ID="chkRFI" runat="server" Text="RFI" />
</div>
<div class="boxbody">
<asp:CheckBoxList ID="chklstRFI" runat="server" CssClass="boxbodylist">
<asp:ListItem Text="RFI No" Value="RFI" />
<asp:ListItem Text="RFI Date" Value="RFI_Date" />
</asp:CheckBoxList>
</div>
</div>
</div>
How to solve?怎么解决? Please provide me any ideas... Thanks请给我任何想法...谢谢
You should use $('#<%= chkRFI.ClientID %>')
instead of $('#chkRFI')
您应该使用$('#<%= chkRFI.ClientID %>')
而不是$('#chkRFI')
I feel that solution by ysrb should work - but you may also try alternate selectors - for example:我觉得 ysrb 的解决方案应该可以工作 - 但您也可以尝试备用选择器 - 例如:
var checkAll = $('.boxheader input');
checkAll.click(function() {
$('.boxbody input').attr('checked', checkAll.attr('checked'));
});
If you are using ASP.NET then all element IDs will be generated in very ugly form, eg $Form1$$MyCheckBox (in is not exactly the correct sample, but it shows the main idea).如果您使用的是 ASP.NET,那么所有元素 ID 都将以非常丑陋的形式生成,例如 $Form1$$MyCheckBox (不完全正确的示例,但它显示了主要思想)。 If you are using ASP.NET 4 you can disable this feature in web.config ([pages clientIDMode="static" /]).如果您使用的是 ASP.NET 4,您可以在 web.config ([pages clientIDMode="static" /]) 中禁用此功能。 Analyze your checkbox with FireBug or simply view the page source to make sure that checkbox was generated with correct ID.使用 FireBug 分析您的复选框或简单地查看页面源以确保生成的复选框具有正确的 ID。 Hope this helps...希望这可以帮助...
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Check/Uncheck All CheckBoxes Using JQuery</title>
<script src="Scripts/jquery-1.2.6.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#chkAll').click(
function() {
$("INPUT[type='checkbox']").attr('checked', $('#chkAll').is(':checked'));
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox ID="chkAll" runat="server" Text="Check All" /><br />
<asp:CheckBoxList ID="cbList" runat="server">
</asp:CheckBoxList>
</div>
</form>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.