我是新來的JS和課堂作業,需要工作:鍵,循環3狀態改變
當用戶點擊該按鈕高亮顯示應用CSS類所有其他li元素,所以你得到的顏色交替,並使圖像出現。
我無法使顏色更改切換到正常工作狀態,我也無法將圖像顯示出來。
<script>
var colors = new Array()
colors[0] = "#cc0099";
colors[1] = "#a4c400";
colors[2] = "#9900cc";
var counter = 0;
window.onload = function()
{
var highlightBtn= document.getElementById("highlight_btn");
highlightBtn.onclick = switchColors;
}
function switchColors()
{
var imgSrc = "images/" + [i];
var changeLI = document.getElementsByClassName("change");
changeLI.innerHTML = counter;
counter++;
}
</script>
<h1>Happy Mothers Day!</h1>
<h2>Things to get Mom:</h2>
<ul>
<li class="change">New Plants</li>
<li>Flowers</li>
<li class="change">A Day at the Spa</li>
<li>A Picture of Yourself</li>
<li class="change">New Shoes!</li>
<li>Anything with a Heart on It</li>
<li class="change"> Chocolate</li>
</ul>
<input id="highlight_btn" type="button" value="Highlight">
我是從我的筆記複製和那是我的document.getElementsbyClassName簡寫。我已經修好了。 – 2013-05-06 13:49:09
var imgSrc =「images /」+ [i];應該是var imgSrc =「images /」+ images [counter];然後你也需要一個圖像數組。此外,您嘗試將計數器的值分配給LI數組 – mplungjan 2013-05-06 13:57:32