使用 JavaScript 在隐藏和显示元素之间切换。
切换隐藏和显示
切换(隐藏/显示)元素
第一步 - 添加 HTML:
<button onclick="myFunction()">Click Me</button>
<div id="myDIV"> This is my DIV element. </div> 第二步 - 添加 JavaScript:
function myFunction() {
var x = document.getElementById("myDIV"); if (x.style.display === "none") { x.style.display = "block"; else { } x.style.display = "none"; {} {}
相关页面
教程:CSS 显示