我創建了一個JavaScript的運動改變HTML對象的ID。JavaScript的問題無法使用功能與HTML標籤
我想建立一個按鈕,將選擇之間循環。此時按鈕不執行該功能。
請看看代碼,讓我知道我做錯了。
a = 0;
n = 1;
i = 0;
function changexc(a, n) {
document.getElementById('effect00').id = "effect00" + (a + i);
}
function counterxc() {
i = n++;
return n;
}
document.write("<br>" + "a is " + a + "<br>");
document.write(" i is " + i + "<br>");
document.write(" n is " + n + "<br>");
document.write(" n + a is " + (n + a) + "<br>");
changexc(a);
<style>#effect001 {
max-width: 100px!important;
height: 200px;
background-color: red;
display: block;
}
#effect002 {
max-width: 200px!important;
height: 100px;
background-color: blue;
display: block;
}
#effect003 {
max-width: 300px!important;
height: 300px;
border-radius: 50%;
background-color: yellow;
display: block;
}
</style>
<div id="effect00"></div>
<button type="button" id="thatdarnbutton" onclick="counterxc()">Click Me</button>
它是否拋出任何錯誤?你在哪裏包括JavaScript?在頭部還是身體的盡頭? –
我想你應該調用'changexc'函數而不是在onclick函數中返回'n'。 – nocodename
從我所看到的,你的'counterxc'只設置一個變量爲某個值......這就是它 – Lixus