我有一个带有3个复选框和按钮的gridview。我想在jquery中写以下条件:
如果选中了复选框1,则将自动禁用复选框2,并自动选中复选框3
如果选中了复选框2,则将自动禁用复选框1,并且将自动选中复选框3
如果没有选中复选框1和复选框2,则它们将自动启用,而复选框3将被自动取消
只有在复选框1和2之一被选中时,复选框3才会自动选中
不必同时选中复选框1和复选框2。
如果选中了网格视图的所有复选框3,则按钮的状态应更改为就绪。
谢谢
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />
<script type="text/javascript">
function selectedChk(chkbox) {
var chk1 = document.getElementById(chkbox);
var chk2 = document.getElementById(chkbox);
var chk3 = document.getElementById(chkbox);
if (chk1.checked == true)
{
chk2.disabled = true
chk2.checked == false
chk3.checked == true
}
else if (chk2.checked == true)
{
chk1.disabled = true
chk1.checked == false
chk3.checked == true
}
else{
chk3.checked == false
}
}
</script>
<asp:UpdatePanel ID="myPanel" runat="server">
<ContentTemplate>
<asp:GridView ID="gwd" runat="server" CellPadding="1" CssClass="gwd" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField SortExpression="chk1">
<HeaderTemplate>
chk1
<br />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk1" runat="server" onclick="selectedChk(this)" Checked='<%# Bind("chk1") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="chk2">
<HeaderTemplate>
chk2
<br />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk2" runat="server" onclick="selectedChk(this)" Checked='<%# Bind("chk2") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="chk3">
<HeaderTemplate>
chk3
<br />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk3" runat="server" onclick="selectedChk(this)" Checked='<%# Bind("chk3") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="btn" runat="server" CausesValidation="false" CommandName="not ready"
Text="not ready" DataBinding="OnDataBinding" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID" SortExpression="id">
<ItemTemplate>
<asp:Label ID="id" Width="0" runat="server" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>