50分求教控件显示的简单问题
我有一堆服务器端控件。想另外设置一个checkbox或者超级链接什么的。点一下显示那一堆控件,再点一下就隐藏那堆控件。最好不要刷新页面。大家有办法吗?
------解决方案--------------------可以将控件分放到不同的panel控件中,然后在服务器端根据需要设置
panel1.Style[ "display "] = " ";//显示:可见
panel2.Style[ "display "] = "none ";//不显示:不可见
当你点击checkbox(id= "chk1 ")时在客户端写一个函数
function setVisible()
{
if (document.all.chk1.checked)
{
panel1.Style[ "display "] = "none ";
panel2.Style[ "display "] = " ";
}
else
{
panel1.Style[ "display "] = " ";
panel2.Style[ "display "] = "none ";
}
}
------解决方案-------------------- <div id=div1 style= "display:none "> .... </div>
<input type= "button " onclick=return aa(); value=show/>
function aa()
{
if(document.getElementById(div1).style.display= "none ")
document.getElementById(div1).style.display= "inline ";
else
document.getElementById(div1).style.display= "none ";
}
------解决方案--------------------通过 CSS 的 display 属性控制
<div id=div1>
hello
<asp:textbox id=t runat=server />
...
</div>
<input type=checkbox onclick=showHide(this); value=hide />
function showHide(sender)
{
var targetDiv = document.getElementById(div1);
targetDiv.style.display = (targetDiv.style.display == " ") ? "block " : " ";
sender.value = (sender.value == "hide " : "show " : "hide ";
}
------解决方案-------------------- <html>
<body>
<input id= "btn " type= "button " value= "button " onclick= "var b;b=document.getElementById(test);if (b.style.display== 'none '){b.style.display= 'block ';} else {b.style.display= 'none ';} "/>
<div id= "test ">
你的控件
</div>
</body>
</html>