CSS的display属性,显示或隐藏元素

时间:2023-12-31 22:18:44
<html>
<head>
<script type="text/javascript">
function removeElement() {
document.getElementById("p1").style.display = "none";
document.getElementById("d1").style.display = "none";
}
function showElement() {
document.getElementById("p1").style.display = "block";
document.getElementById("d1").style.display = "block";
}
</script>
</head>
<body> <h1>This is a header</h1>
<div id="d1">xxxxxxxxxxxxxxxxxxxxxxxxxx</div>
<p id="p1">This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.
This is some text. This is some text. This is some text.</p> <input type="button" onclick="removeElement()" value="Do not display paragraph" />
<input type="button" onclick="showElement()" value="display paragraph" />
</body>
</html>