两个checkbox互斥的问题
页面上放了两个checkbox
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged"/>
<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True" oncheckedchanged="CheckBox2_CheckedChanged"/>
后台代码如下:
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox2.Checked)
{
this.CheckBox1.Checked = false;
this.textbox1.Visible = true;
}
else
{
this.CheckBox1.Checked = true;
this.textbox1.Visible = false;
}
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
this.CheckBox2.Checked = false;
this.textbox1.Visible = false;
}
else
{
this.CheckBox2.Checked = true;
this.textbox1.Visible = true;
}
}
感觉没什么问题,可是我点击任何一个checkbox都没反应,这是怎么回事啊
------解决方案--------------------
JScript code
function forCheck1(cb) {
alert(cb);
var cb2 = document.getElementById("<%=CheckBox2.ClientID %>");
cb2.checked = !cb.checked
}
function forCheck2(cb) {
var cb1 = document.getElementById("<%=CheckBox1.ClientID %>");
cb1.checked = !cb.checked
}