$(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">
开发者_如何学Go <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')
I feel that solution by ysrb should work - but you may also try alternate selectors - for example:
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, e.g. $Form1$$MyCheckBox (in is not exactly the correct sample, but it shows the main idea). If you are using ASP.NET 4 you can disable this feature in 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. 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>
here is the complete example
精彩评论