我将复制了w3schools的隐藏和显示切换,但我希望它被反转,这样额外的信息就不会从一开始就存在,而是通过按钮显示。
以下是代码:
HTML:
<button onclick="myFunction()">Click Me</button>
<div id="myDIV">
This is my DIV element.
</div>
js:
function myFunction() {
var x = document.getElementById('myDIV');
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
任何帮助都将不胜感激!
#myDIV
元素最初具有display: none
(使其隐藏),而不是在开始时显示?此外,我在这里看不到任何jQuery,您不需要添加标签。 - Spencer Wieczorekdocument.getElementById('myDIV').style.display = "none";
将其设置为从一开始就不显示。 - Jack Parkinson