高分~更改服务器控件状态之后,禁用客户端控件。如图!!
如果下拉框选择的是查询员,则禁用所以复选框。如果不是则启用。
大侠们给点解决方案。谢谢
[最优解释]
页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ULTest.aspx.cs" Inherits="ULTest" %>
<!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="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
//方法1: jquery
function test_jQuery(obj){
$("#div1 :checkbox").prop("disabled",obj.value==="3");
}
//方法2: 纯js
function test(obj){
var chks = document.getElementById("div1").getElementsByTagName("input");
for(var i=0;i<chks.length;i++){
if(obj.value==="3"){
chks[i].setAttribute('disabled','disabled');
}else{
chks[i].removeAttribute('disabled');
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="请选择" Value=""></asp:ListItem>
<asp:ListItem Text="录入员" Value="1"></asp:ListItem>
<asp:ListItem Text="管理员" Value="2"></asp:ListItem>
<asp:ListItem Text="查询员" Value="3"></asp:ListItem>
</asp:DropDownList>
<div id="div1" >
<input type="checkbox" />财务部<br />
<input type="checkbox" />审计部<br />
<input type="checkbox" />纪委<br />
</div>
</form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class ULTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.DropDownList1.Attributes.Add("onchange","test(this)");
}
}
}
if (DropDownList1.SelectedItem.Text != "查询员")
{
//不是,启用
CheckBox1.Enabled = true;
}
else
{
//是,禁用
CheckBox1.Enabled = false;
}