日期:2014-05-18 浏览次数:20979 次
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { CheckBox2.Checked = !CheckBox1.Checked; } protected void CheckBox2_CheckedChanged(object sender, EventArgs e) { CheckBox1.Checked = !CheckBox2.Checked; }
------解决方案--------------------
用jq 控制 挺简单的
<head id="Head1" runat="server"> <title></title> <script src="jquery-1.7.1.min.js" type="text/javascript"></script> </head> <body> <form id="form1" runat="server"> <asp:CheckBox ID="TextBox1" runat="server" /> <asp:CheckBox ID="TextBox2" runat="server" /> </form> <script type="text/javascript"> $(document).ready(function () { $(":checkbox").click(function(){ $(":checkbox").reomveAttr("checked"); $(this).attr("checked","checked"); }) }) </script> </body> </html>
------解决方案--------------------
不想刷屏可以用下面的客户端代码:
假设有两个checkBox,分别代表性别:
function TestMale() {
var chkMale = document.getElementById("chkMale");
var chkFemale = document.getElementById("chkFemale");
chkFemale.checked = !chkMale.checked;
}
function TestFemale() {
var chkMale = document.getElementById("chkMale");
var chkFemale = document.getElementById("chkFemale");
chkMale.checked = !chkFemale.checked;
}