我已經添加了一個可摺疊的div到我的圖像。它只適用於一個圖像。如何使用Javascript創建可摺疊的div?
如果我再添加一張它不工作:
function expand(showHideDiv, switchTextDiv) {
var ele = document.getElementById(showHideDiv);
var text = document.getElementById(switchTextDiv);
if (ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "+";
} else {
ele.style.display = "block";
text.innerHTML = "-";
}
}
<h1 class="expand">Chart1<a id="expand" href="javascript:expand('expand-content','expand');" >+</a></h1>
<div id="expand-content" style="display: none;">
<img src="imagelink" width="100%">
</div>
<h1 class="expand">Chart2<a id="expand" href="javascript:expand('expand-content','expand');" >+</a></h1>
<div id="expand-content" style="display: none;">
<img src="imagelink" width="100%">
</div>
請使用不同的ID對於每個圖像Y兩者都不能有相同的ID – WisdmLabs