【javaWeb】显示和隐藏div
2012-07-30 17:31
218 查看
一、效果展示
1、初始状态,效果
2、点击“显示或隐藏”连接,效果
3、再次点击“显示或隐藏”连接,效果
二、实现代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>显示隐藏div</title>
<script type="text/javascript">
function isShowSecond(firstId,secondId){
var flag = document.getElementById(firstId).value;
if(flag == 'false'){
document.getElementById(secondId).style.display="";
document.getElementById(firstId).value="true";
}else{
document.getElementById(firstId).value="false";
document.getElementById(secondId).style.display="none";
}
}
</script>
</head>
<body>
<div style="width:150px;height:31px;border: 1px solid red;">
<input type="hidden" id="firstDiv"value="false"
/>
<a href="javascript:isShowSecond('firstDiv','secondDiv')" style="width:100px;height:31px; border: 1px solid red;">显示或隐藏
</a>
<div id="secondDiv" style="display: none; padding-left: 30px;">
<div style="width:100px;height:31px; border: 1px solid red;">
<a href="javascript:">二级div</a>
</div>
<div style="width:100px;height:31px; border: 1px solid red;">
<a href="javascript:">二级div2</a>
</div>
</div>
</div>
</body>
</html>
备注:
1、本示例未关注样式
2、彩色标注突出重点
1、初始状态,效果
2、点击“显示或隐藏”连接,效果
3、再次点击“显示或隐藏”连接,效果
二、实现代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>显示隐藏div</title>
<script type="text/javascript">
function isShowSecond(firstId,secondId){
var flag = document.getElementById(firstId).value;
if(flag == 'false'){
document.getElementById(secondId).style.display="";
document.getElementById(firstId).value="true";
}else{
document.getElementById(firstId).value="false";
document.getElementById(secondId).style.display="none";
}
}
</script>
</head>
<body>
<div style="width:150px;height:31px;border: 1px solid red;">
<input type="hidden" id="firstDiv"value="false"
/>
<a href="javascript:isShowSecond('firstDiv','secondDiv')" style="width:100px;height:31px; border: 1px solid red;">显示或隐藏
</a>
<div id="secondDiv" style="display: none; padding-left: 30px;">
<div style="width:100px;height:31px; border: 1px solid red;">
<a href="javascript:">二级div</a>
</div>
<div style="width:100px;height:31px; border: 1px solid red;">
<a href="javascript:">二级div2</a>
</div>
</div>
</div>
</body>
</html>
备注:
1、本示例未关注样式
2、彩色标注突出重点
相关文章推荐
- web前端,js实现div隐藏显示
- selenium2+webdriver+java利用firepath定位隐藏div中的问题
- js隐藏显示div
- div 隐藏和显示
- jquery点击按钮显示和隐藏DIv
- 前端div的显示隐藏、Jquery input只读
- java web 入门实例servlet篇(显示后台数据库列表,删除某一条记录并显示)
- Java WEB开发时struts标签 显示set内容
- 后台.cs 页面控制 前台 DIV 显示或隐藏 方法
- 如何点击按钮显示隐藏div,再点击收起,默认隐藏
- JQuery通过radio,select改变隐藏显示div
- JS+CSS简单实现DIV遮罩层显示隐藏
- [Web前端技术教学]盒子的隐藏和显示
- 后台控制DIV的显示与隐藏
- ASP.NET div信息提示框显示几秒后隐藏
- div 隐藏和显示
- Web开发中的显示与隐藏
- div显示隐藏
- jquery点击区域显示或隐藏DIV,点击非该DIV的地方隐藏该DIV
- 让一组div显示和隐藏的jquery特效