使用 display 属性操作元素
Manipulating elements using the display property
<!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
"消失并且"第二"取而代之(确切位置),反之亦然。
请帮忙吗?
<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>
相关文章:
- 操作放置在画布上的元素之间的连接
- 如何操作iframe之外的元素
- jQuery-将列表项的一个元素移动到同一项的另一个元素中+对我的列表中的每个项执行此操作
- 元素未使用当前玩家操作进行更新
- 单击元素两次后执行操作
- toogleClass函数来切换元素类并在事件期间执行某些操作
- Rails-带有单选按钮的表单,带有启用/禁用附加元素的javascript操作
- 为什么在ASP.NET Ajax更新面板中执行任何操作后javascript元素都停止工作
- 在使用jQuery第二次单击元素类后开始操作
- 如何在创建某个元素时对其进行操作
- 创建一个本地脚本来操作网站中的DOM元素
- 从HTML表单中获取计算得到的JavaScript数据,并将其作为新元素添加到相同的表单操作中以使用PHP保存
- 这是关于Jquery/JS的,如果我改变元素's HTML-我可以对它执行其他Jquery/JS操作吗
- 如何使用 JavaScript 操作 html 按钮元素的“onclick”事件
- 如何动态操作jquery可拖动UL元素的内容
- 使用javascript操作css元素,左短划线
- jQuery 元素操作不会刷新元素
- D3:基于svg元素操作更改数据
- Javascript中的元素操作
- 如何使用切换元素操作 alert()