我尝试了这个: https: //jsfiddle.net/eu30mcps/,但它不起作用。当我单击第一个按钮时,如何显示div
第一个...等等?
function DisplayKat1() {
var x = document.getElementById("kat1");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
function DisplayKat2() {
var x = document.getElementById("kat2");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
function DisplayKat3() {
var x = document.getElementById("kat3");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
<p>
<button class="btn default" onklick="DisplayKat1()">A</button>
<button class="btn default" onklick="DisplayKat2()">B</button>
<button class="btn default" onklick="DisplayKat3()">C</button>
</p>
<div id="kat1">
Text A
</div>
<div id="kat2">
Text B
</div>
<div id="kat3">
Text C
</div>
慕码人2483693
相关分类