层隐藏,层显示问题

chen505586338 2012-05-31 01:38:43
页面中有两个tr分别放在两个div中,有一个select下拉框,当我选下拉框里第二个值时,其 中一个div隐藏,当我选第四个值时,两个div都要隐藏,怎么实现,求助啊!!
...全文
61 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
rfheh 2012-06-01
  • 打赏
  • 举报
回复
看看是不是你想要的效果
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>正则表达式30分钟入门教程</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 13px}
-->
</style>
</head>

<body>
<script>
function hideOrShow(){
var sel = document.getElementById("sel").value;
var first = document.getElementById("first");
var second = document.getElementById("second");
if(sel=="0"){
first.style.display="block";
second.style.display="none";
}else if(sel=="1"){
first.style.display="none";
second.style.display="block";
}else if(sel=="2"){
first.style.display="none";
second.style.display="none";
}else if(sel=="3"){
first.style.display="block";
second.style.display="block";
}
}
</script>
选择下列框<select onchange="hideOrShow()" id="sel">
<option value="0">隐藏第二个DIV</option>
<option value="1">隐藏第一个DIV</option>
<option value="2">都隐藏</option>
<option value="3">都显示</option>
</select>
<table>
<tr><td><div id="first">第一个层显示</div></td></tr>
<tr><td><div id="second">第二个层显示</div></td></tr>
</table>
</body>
</html>
testvon 2012-05-31
  • 打赏
  • 举报
回复
select标签有这个属性 onchange="javascript:location.href=this.value;",作用是当下拉框内容改变时执行<option value="xxx">中的内容.
div 标签有这个属性 style="display: none",其中none为不显示DIV,block为显示该DIV
你要实现的功能可以先在相应的option中调用JS方法去改变你想显示隐藏的DIV的属性

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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