HTML5的div展开与收缩
直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>展开与收缩</title>
</head>
<body>
<div>
<div>
你好hello
</div>
<div id="change" style="display:none">
你好hi
</div>
</div>
<p class="slide">
<a href="javascript:showdiv();" id="control" class="btn-slide">展开+</a>
</p>
<script type="text/javascript">
function showdiv() {
document.getElementById("change").style.display = "block";
document.getElementById("control").innerHTML = "收起-";
document.getElementById("control").href = "javascript:hidediv()";
}
function hidediv() {
document.getElementById("change").style.display = "none";
document.getElementById("control").innerHTML = "展开+";
document.getElementById("control").href = "javascript:showdiv()";
}
</script>
</body>
</html>
总结
display:none
的作用是进入页面是默认隐藏div
而
display:block
的作用是解除隐藏div
,显示div