[100分]客户端checkboxlist选定项改变事件 我想用javascript根据checkboxlist的选定项中是否有指定项(如“天气”),来控制一个dropdownlist控件是否显示,不能在后台写,因为不想刷新页面。checkboxlist的datasource是从数据库绑定的,因为数量是动态的,所以不能用checkbox 有没有什么好的实现办法?还请大家多帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 asp.net2.0还是以前的?asp.net2.0可以直接使用Attributes.Add("onclick","jsMethod();return false");实现 ajax,想不刷新用前台控件去改变后台控件,用传统办法行不通 <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load( object sender, EventArgs e ) { if (!Page.IsPostBack) { string[] a = {"A","B"}; CheckBoxList1.DataSource = a; CheckBoxList1.DataBind(); for (int i = 0 ; i < CheckBoxList1.Items.Count ; i++) { if (CheckBoxList1.Items[i].Text == "A") { CheckBoxList1.Items[i].Attributes.Add("onclick", "document.getElementById('" + DropDownList1.ClientID + "').style.display='block'"); } else { CheckBoxList1.Items[i].Attributes.Add("onclick", "document.getElementById('" + DropDownList1.ClientID + "').style.display='none'"); } } } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title></head><body> <form id="form1" runat="server"> <div> <asp:CheckBoxList ID="CheckBoxList1" runat="server"> </asp:CheckBoxList></div> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> </form></body></html> <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load( object sender, EventArgs e ) { if (!Page.IsPostBack) { string[] a = { "天气", "B", "C"}; CheckBoxList1.DataSource = a; CheckBoxList1.DataBind(); for (int i = 0 ; i < CheckBoxList1.Items.Count ; i++) { if (CheckBoxList1.Items[i].Text == "天气") { CheckBoxList1.Items[i].Attributes.Add("onclick", "document.getElementById('" + DropDownList1.ClientID + "').style.display='none'"); } else { CheckBoxList1.Items[i].Attributes.Add("onclick", "document.getElementById('" + DropDownList1.ClientID + "').style.display=''"); } } } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title></head><body> <form id="form1" runat="server"> <div> <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="false"> </asp:CheckBoxList></div> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> </form></body></html> 或者<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load( object sender, EventArgs e ) { if (!Page.IsPostBack) { string[] a = { "天气", "B", "C"}; CheckBoxList1.DataSource = a; CheckBoxList1.DataBind(); for (int i = 0 ; i < CheckBoxList1.Items.Count ; i++) { if (CheckBoxList1.Items[i].Text == "天气") { CheckBoxList1.Items[i].Attributes.Add("onclick", "if(this.checked) {document.getElementById('" + DropDownList1.ClientID + "').style.display='none'}else{document.getElementById('" + DropDownList1.ClientID + "').style.display=''}"); } } } }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>无标题页</title></head><body> <form id="form1" runat="server"> <div> <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="false"> </asp:CheckBoxList></div> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> </form></body></html>也可以这样<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load( object sender, EventArgs e ) { if (!Page.IsPostBack) { string[] a = { "天气", "B", "C" }; CheckBoxList1.DataSource = a; CheckBoxList1.DataBind(); for (int i = 0 ; i < CheckBoxList1.Items.Count ; i++) { CheckBoxList1.Items[i].Attributes.Add("onclick", "ClickMe(this)"); } } }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> <script type="text/javascript"> function ClickMe(o) { var boxid = "<%=CheckBoxList1.ClientID %>" var boxs = document.getElementsByTagName("INPUT") for(i = 0;i<boxs.length;i++) { if(boxs[i].id.substr(0,boxid.length) == boxid) { var chname = boxs[i].nextSibling.innerHTML if(chname == "天气" && boxs[i].checked) { document.getElementById('<%=DropDownList1.ClientID%>').style.display='none'; break; } else { document.getElementById('<%=DropDownList1.ClientID%>').style.display=''; } } } } </script></head><body> <form id="form1" runat="server"> <div> <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="false"> </asp:CheckBoxList></div> <asp:DropDownList ID="DropDownList1" runat="server"> </asp:DropDownList> </form></body></html>随你的需要而定 前台如果用了protected void Page_Load( object sender, EventArgs e ),后台的就被屏蔽了,能把前台的换个名字吗?也让它在初始化页面时执行? 另外因为页面继承了master页,所以没有body,没法用onload事件 OnClick该成OnCheckedChanged事件试试 OnClick该成OnCheckedChanged事件试试============================试过,不行 uping............................................................................................小女帮你顶一次 另外因为页面继承了master页,所以没有body,没法用onload事件??总的页面是有的window.onload=function(){alert("ok")}服务器端的Page_Load更没有问题 图片播放功能 gridview关键字高亮 编码求助呢 请问如何实现带格式复制。 一道关于数组的面试题!!! 简单问题,送分了 ?????ASP.NET datagrid里删除按钮怎么让不可用 问一个比较初级的问题 能不能用.net做一些web service 给linux调用啊? 入门ASP.NET问题 使用ASP.NET+SQL显示有图片的文字 asp.net c#参数传递跟全局变量
asp.net2.0可以直接使用Attributes.Add("onclick","jsMethod();return false");实现
{
if (!Page.IsPostBack)
{
string[] a = {"A","B"};
CheckBoxList1.DataSource = a;
CheckBoxList1.DataBind();
for (int i = 0 ; i < CheckBoxList1.Items.Count ; i++)
{
if (CheckBoxList1.Items[i].Text == "A")
{
CheckBoxList1.Items[i].Attributes.Add("onclick", "document.getElementById('" + DropDownList1.ClientID + "').style.display='block'");
}
else
{
CheckBoxList1.Items[i].Attributes.Add("onclick", "document.getElementById('" + DropDownList1.ClientID + "').style.display='none'");
}
}
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList></div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</form>
</body>
</html>
{
if (!Page.IsPostBack)
{
string[] a = { "天气", "B", "C"};
CheckBoxList1.DataSource = a;
CheckBoxList1.DataBind();
for (int i = 0 ; i < CheckBoxList1.Items.Count ; i++)
{
if (CheckBoxList1.Items[i].Text == "天气")
{
CheckBoxList1.Items[i].Attributes.Add("onclick", "document.getElementById('" + DropDownList1.ClientID + "').style.display='none'");
}
else
{
CheckBoxList1.Items[i].Attributes.Add("onclick", "document.getElementById('" + DropDownList1.ClientID + "').style.display=''");
}
}
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="false">
</asp:CheckBoxList></div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</form>
</body>
</html>
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load( object sender, EventArgs e )
{
if (!Page.IsPostBack)
{
string[] a = { "天气", "B", "C"};
CheckBoxList1.DataSource = a;
CheckBoxList1.DataBind();
for (int i = 0 ; i < CheckBoxList1.Items.Count ; i++)
{
if (CheckBoxList1.Items[i].Text == "天气")
{
CheckBoxList1.Items[i].Attributes.Add("onclick", "if(this.checked) {document.getElementById('" + DropDownList1.ClientID + "').style.display='none'}else{document.getElementById('" + DropDownList1.ClientID + "').style.display=''}");
}
}
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="false">
</asp:CheckBoxList></div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</form>
</body>
</html>
也可以这样<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load( object sender, EventArgs e )
{
if (!Page.IsPostBack)
{
string[] a = { "天气", "B", "C" };
CheckBoxList1.DataSource = a;
CheckBoxList1.DataBind();
for (int i = 0 ; i < CheckBoxList1.Items.Count ; i++)
{
CheckBoxList1.Items[i].Attributes.Add("onclick", "ClickMe(this)");
}
}
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script type="text/javascript">
function ClickMe(o)
{
var boxid = "<%=CheckBoxList1.ClientID %>"
var boxs = document.getElementsByTagName("INPUT")
for(i = 0;i<boxs.length;i++)
{
if(boxs[i].id.substr(0,boxid.length) == boxid)
{
var chname = boxs[i].nextSibling.innerHTML
if(chname == "天气" && boxs[i].checked)
{
document.getElementById('<%=DropDownList1.ClientID%>').style.display='none';
break;
}
else
{
document.getElementById('<%=DropDownList1.ClientID%>').style.display='';
}
}
}
}
</script></head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="false">
</asp:CheckBoxList></div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</form>
</body>
</html>随你的需要而定
============================
试过,不行
总的页面是有的window.onload=function(){alert("ok")}
服务器端的Page_Load更没有问题