关于一个CheckBoxList和javascript的问题,请各位大虾帮帮忙!谢谢了!

wsh236 2006-07-12 11:08:09
有一个CheckBoxList 有三个选项 1 2 3 另外有三个隐藏的CheckBoxList 分别是CheckBoxList1,CheckBoxList2 ,CheckBoxList3 问题是怎么用javascript实现CheckBoxList 如果选定1 ,CheckBoxList1就会显示出来,如果选2 CheckBoxList2 就会显示出来 ,如果选3 CheckBoxList3 就会显示出来。先谢谢了!如果分不够可以在加分!
...全文
468 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
wsh236 2006-07-13
  • 打赏
  • 举报
回复
好像ListItem里面没有onclick事件啊!呵呵 !
wsh236 2006-07-13
  • 打赏
  • 举报
回复
nickppa(张) 把那个if(!IsPostBack)去掉我也实验了 也是不行的!你肯定自己没有测试 晕了!
好像偶运行的时候 Page_Load里面的代码都没有反应阿!
nickppa 2006-07-13
  • 打赏
  • 举报
回复
你可以在运行的IE中右键查看源程序,你可以看到ListItem就是一个个checkBox,html中显示<input type="checkBox" onclick="..." />,那个Attributes.Add方法的意思就是这个用处。
nickppa 2006-07-12
  • 打赏
  • 举报
回复
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2003.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script>
function myClick(chkItem, divname)
{
if(chkItem.checked)
{
document.getElementById(divname).style.display = "block";
}
else
{
document.getElementById(divname).style.display = "none";
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:CheckBoxList id="CheckBoxList" runat="server">
<asp:ListItem Value="Div1">AAA</asp:ListItem>
<asp:ListItem Value="Div2">BBB</asp:ListItem>
<asp:ListItem Value="Div3">CCC</asp:ListItem>
</asp:CheckBoxList>
<div id="Div1" style="DISPLAY: none">aa<asp:CheckBoxList id="CheckBoxList1" runat="server"></asp:CheckBoxList></div>
<div id="Div2" style="DISPLAY: none">bb<asp:CheckBoxList id="CheckBoxList2" runat="server"></asp:CheckBoxList></div>
<div id="Div3" style="DISPLAY: none">cc<asp:CheckBoxList id="CheckBoxList3" runat="server"></asp:CheckBoxList></div>
</form>
</body>
</HTML>

-------------------------------------------------------------------------------

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
foreach(ListItem lstItem in CheckBoxList.Items)
{
lstItem.Attributes.Add("onclick", "myClick(this, '" + lstItem.Value + "');");
}
}
}
zhangxiaopin 2006-07-12
  • 打赏
  • 举报
回复
function DispalyCheckBoxList()
{
var varckblist1=document.all("ckblistone");
var varckblist2=document.all("ckblisttwo");
var varckblist3=document.all("ckblistthrww");
var choices=document.all("drplist");
switch(choices)
{
case 1:
varckblist1.style.dispaly="";
varckblist2.style.dispaly="none";
varckblist3.style.dispaly="none";
break;
case 2:
varckblist1.style.dispaly="none";
varckblist2.style.dispay="";
varckblist3.style.dispaly="none";
break;
case 3:
varckblist1.style.dispaly="none";
varckblist2.style.dispaly="none";
varckblist3.style.dispaly="";
break;
default:
varckblist1.style.dispaly="";
varckblist2.style.dispaly="none";
varckblist3.style.dispaly="none";
break;
}
}

//****调用函数
sandsboy 2006-07-12
  • 打赏
  • 举报
回复
1.服务器编程(CheckBoxList0的AutoPostBack为true)
CheckBoxList1.Visible = CheckBoxList0.Items[0].Selected;
CheckBoxList2.Visible = CheckBoxList0.Items[1].Selected;
CheckBoxList3.Visible = CheckBoxList0.Items[2].Selected;
2.客户端编程
var t = document.getElementById(CheckBoxList0.ClientID%>");
document.getElementById("<%=CheckBoxList1.ClientID%>").style.visible = t.rows[0].cells[0].children[0].checked;
document.getElementById("<%=CheckBoxList2.ClientID%>").style.visible = t.rows[1].cells[0].children[0].checked;
document.getElementById("<%=CheckBoxList3.ClientID%>").style.visible = t.rows[2].cells[0].children[0].checked;
dreamwaters 2006-07-12
  • 打赏
  • 举报
回复
<script language="javascript">
function A()
{
document.all("CheckBoxList1").style.display='none';
document.all("CheckBoxList2").style.display='none';
document.all("CheckBoxList3").style.display='none';

var chk=document.getElementById("CheckBoxList"+document.getElementById("CheckBoxList").value);
chk.style.display='';
}
</script>
wsh236 2006-07-12
  • 打赏
  • 举报
回复
我也搜了 没有找到阿!同志们你们怎么就不回答问题呢!我真的很怀疑了。
CheckBoxList用
baobei7758 2006-07-12
  • 打赏
  • 举报
回复
<script language="javascript">
function changeFun()
{
var ck1= document.getElementById("CheckBoxList_0");
var ck2= document.getElementById("CheckBoxList_1");
var ck3= document.getElementById("CheckBoxList_2");

if (ck1.checked)
{
document.all("CheckBoxList1").style.display="inline";
}
if (ck2.checked)
{
document.all("CheckBoxList2").style.display="inline";
}
if (ck3.checked)
{
document.all("CheckBoxList3").style.display="inline";
}

}
</script>
francsescoli 2006-07-12
  • 打赏
  • 举报
回复
有人问过了,搜索一下.
yizhixiaozhu 2006-07-12
  • 打赏
  • 举报
回复
用javascript
如果不想回发的话

wsh236 2006-07-12
  • 打赏
  • 举报
回复
我这里没有书啊,老兄 你认为简单 就解决问题撒。
xczgb 2006-07-12
  • 打赏
  • 举报
回复
up 很简单。看看书
wsh236 2006-07-12
  • 打赏
  • 举报
回复
咋没有人回答呢!??高手呢!都去哪里了????
nickppa 2006-07-12
  • 打赏
  • 举报
回复
有没有写Page_Load啊?把那个if(!IsPostBack)去掉试试看,我这个多加了。
wsh236 2006-07-12
  • 打赏
  • 举报
回复
揭帖 to nickppa(张) 请你看看你的程序为什么显示不了 我感觉你写的很好!
myminimouse 2006-07-12
  • 打赏
  • 举报
回复
up
wsh236 2006-07-12
  • 打赏
  • 举报
回复
但是他用的全部是html控件
wsh236 2006-07-12
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Untitled Document</title>
</head>

<body>
<script language="javascript" type="text/javascript">
function adjust(str,obj)
{
document.getElementById(str).style.display = obj.checked?"block":"none";
}
</script>
<table width="500" border="1">
<tr>
<td><input type="checkbox" name="checkbox3" value="checkbox">
忙时优惠包
<input type="checkbox" name="checkbox" value="checkbox" onClick="adjust('line1',this)">
长途优惠包
<input type="checkbox" name="checkbox2" value="checkbox" onClick="adjust('line2',this)">
短信优惠包</td>
</tr>
<tr>
<td id="line1" style="display:none"><input name="radiobutton" type="radio" value="radiobutton">
3
<input name="radiobutton" type="radio" value="radiobutton">
5
<input name="radiobutton" type="radio" value="radiobutton">
10</td>
</tr>
<tr>
<td id="line2" style="display:none"><input name="radiobutton" type="radio" value="radiobutton">
3
<input name="radiobutton" type="radio" value="radiobutton">
6
<input name="radiobutton" type="radio" value="radiobutton">
10</td>
</tr>
</table>
</body>
</html>

这个是我兄弟写的!
wsh236 2006-07-12
  • 打赏
  • 举报
回复
to nickppa(张) 我都按照你的代码写的 为什么实现不了
不知道怎么回事! 当我选择AAA的时候 aa并没有出现阿!
加载更多回复(1)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧