嘗試在單擊按鈕時在不同div之間切換。無法在html中的不同div部分之間切換
<button onclick="myFunction('myDIV')">Try it</button>
<button onclick="myFunction('myDIV2')">Try it 2</button>
<button onclick="myFunction('myDIV3')">Try it 3</button>
這些事業部,我想執行
<div id="myDIV" style="display:none;">
This is my DIV element.
</div>
<div id="myDIV2" style="display:none;">
This is second DIV element.
</div>
<div id="myDIV3" style="display:none;">
This is 3rd DIV element.
</div>
的JavaScript代碼來處理按鈕點擊後點擊它會永遠指向DIV3股利
function myFunction(id) {
var divs = ["myDIV","myDIV2","myDIV3","myDIV4","myDIV5"];
for(i = 0; i < 5; i++){
if(divs[i] == id)
{document.getElementById(id).style.display = "block";}
else
{document.getElementById(id).style.display = "none";}
document.getElementById("debug").innerHTML = divs[i];
}
之間切換,請幫幫我。謝謝。
你怎麼罵你的函數? – CodeIsLife
,點擊這個按鈕 – Sivabushan