更新:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="chkbox_checked_uncheked.aspx.cs"
Inherits="Ediable_Repeater.chkbox_checked_uncheked" %>
<!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></title>
<script src="Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#C1All').click(function () {
debugger
$('.col1').attr("checked", $('#C1All').attr("checked"));
$('.col2').removeAttr("checked");
$('#C2All').removeAttr("checked");
});
$('#C2All').click(function () {
debugger
$('.col2').attr("checked", $('#C2All').attr("checked"));
$('.col1').removeAttr("checked");
$('#C1All').removeAttr("checked");
});
$('.col1').each(function () {
$(this).click(function () {
var id = $(this).attr('id');
debugger
var coresId = id.replace('C1', 'C2');
$('#' + coresId).removeAttr("checked");
$('#C1All').removeAttr("checked");
$('#C2All').removeAttr("checked");
});
});
$('.col2').each(function () {
$(this).click(function () {
var id = $(this).attr('id');
var coresId = id.replace('C2', 'C1');
debugger
$('#' + coresId).removeAttr("checked");
$('#C1All').removeAttr("checked");
$('#C2All').removeAttr("checked");
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<table border="1">
<tr>
<td>
<asp:CheckBox ID="C1All" runat="server" class="col1" Text="approve all" />
</td>
<td>
<asp:CheckBox ID="C2All" runat="server" class="col2" Text="Reject all" />
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="C101" runat="server" class="col1" Text="john 0" />
</td>
<td>
<asp:CheckBox ID="C201" runat="server" class="col2" Text="john 0" />
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="C102" runat="server" class="col1" Text="john 1" />
</td>
<td>
<asp:CheckBox ID="C202" runat="server" class="col2" Text="john all" />
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="C103" runat="server" class="col1" Text="john 2" />
</td>
<td>
<asp:CheckBox ID="C203" runat="server" class="col2" Text="John 2" />
</td>
</tr>
</table>
</div>
</div>
</form>
</body>
</html>
我有两列(全部批准/全部拒绝)我如何限制用户只允许每一个复选框?
这是屏幕的输出:
我尝试过这样的事情但没有奏效:
function SelectApproveAllCheckboxes(chk, selector)
{
$('#<%=gv.ClientID%>').find(selector + " input:checkbox").each(function ()
{
$(this).prop("checked", $(chk).prop("checked"));
});
}
function SelectRejectAllCheckboxes(chk, selector)
{
$('#<%=gv.ClientID%>').find(selector + " input:checkbox").each(function ()
{
$(this).prop("checked", $(chk).prop("checked"));
});
}
<asp:CheckBox ID="chkAll" runat="server" onclick="SelectApproveAllCheckboxes(this, '.approve)" />
<asp:CheckBox ID="chkAll1" runat="server" onclick="SelectRejectAllCheckboxes(this, '.reject)" />