div展开与收起(鼠标点击)

时间:2023-03-08 16:35:32
div展开与收起(鼠标点击)

效果图:

div展开与收起(鼠标点击)

div展开与收起(鼠标点击)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>展开与收起</title>
<style type="text/css">
body{
margin: 0 auto;
padding: 0;
}
#pn{
background: #e8e8e8;
width: 600px;
display: block;
margin: 0 auto;
padding: 5px;
font-size: 9pt;
height: auto;
}
.slide{
margin: 0 auto;
padding: 0;
width: 600px;
border-top: 4px solid gray;
}
.btn-slide{
background: gray;
width:120px;
height: 30px;
text-align: center;
margin: 0 auto;
display: block;
color: #fff;
text-decoration: none;
padding-top: 10px;
}
</style>
<script type="text/javascript">
function showdiv(){
document.getElementById("hpn").style.display="block";
document.getElementById("strHref").innerHTML="收起-";
document.getElementById("strHref").href="javascript:hidediv()";
}
function hidediv(){
document.getElementById("hpn").style.display="none";
document.getElementById("strHref").innerHTML="更多选项+";
document.getElementById("strHref").href="javascript:showdiv()";
}
</script>
</head>
<body>
<div id="pn">
<p>手机商品筛选</p>
<p>网络:移动 联通 电信</p>
<div id="hpn" style="display:none">
<p>价格:5000以上 4000-4999 3000-3999</p>
<p>特点:JDPhone计划‘0’元购机 放水</p>
</div>
</div>
<p class="slide">
<a href="javascript:showdiv();" id="strHref" class="btn-slide">更多选项+</a>
</p>
</body>
</html>