我试图将我的CheckBox
的禁用属性设置为true。但是,当我做回发CheckBox
仍然启用?为什么asp.net复选框没有被禁用?
HTML:
<!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">
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<head runat="server">
<title></title>
<script>
$(document).ready(
function() {
$("#CheckBoxList1_0").attr('disabled',true);
}
);
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
<asp:ListItem>een</asp:ListItem>
<asp:ListItem>twee</asp:ListItem>
<asp:ListItem>drie</asp:ListItem>
</asp:CheckBoxList>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</form>
</body>
</html>
C#:
protected void Button1_Click(object sender, EventArgs e)
{
if (!CheckBoxList1.Items[0].Enabled)
{
Response.Write("it is disabled");
}
}
是否有原因使用CheckBoxList而不是三个单独的CheckBox?如果你使用了一个真正的CheckBox,你可以使用Enabled属性并将其设置为false。 – NoLifeKing 2011-12-23 08:57:51