<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
width: 500px;
height: 500px;
background-color: lightblue;
display: none;
}
#second {
width: 500px;
height: 500px;
background-color: lightblue;
display: none;
}
</style>
</head>
<body>
<button onclick="myFunction()">Try it</button>
<button onclick="myFunction2()">Try this now</button>
<div id="myDIV">
This is my DIV element.
</div>
<div id="second">
This is my DIV2 element.
</div>
<script>
function myFunction() {
document.getElementById("myDIV").style.display = "block";
}
</script>
<script>
function myFunction2() {
document.getElementById("second").style.display = "block";
}
</script>
</body>
</html>因此,我有这样的代码,它将使div元素出现在单击按钮上。然而,我希望一旦我点击“第二”按钮,我希望"myDiv“消失,”第二“取代它的位置(确切的位置),反之亦然。
有什么帮助吗?
发布于 2015-06-11 17:21:29
<script>
function myFunction() {
document.getElementById("myDIV").style.display = "block";
document.getElementById("second").style.display = "none";
}
</script>
<script>
function myFunction2() {
document.getElementById("second").style.display = "block";
document.getElementById("myDIV").style.display = "none";
}
</script>https://stackoverflow.com/questions/30787343
复制相似问题