我有這樣的HTML:JavaScript和querySelector
<div id="allSteps">
<h3>Intermediate steps</h3>
<span class="staticStep">→ <img src="" alt="intermediate step" class="image" ></span>
<span class="staticStep">→ <img src="" alt="intermediate step" class="image"></span>
<span class="staticStep">→ <img src="" alt="intermediate step" class="image"></span>
</div>
在Javascript中,我怎麼訪問的.src爲每個圖像?
我嘗試以下,但它給了我一個錯誤:
document.querySelector(".staticStep img").src[0] = images[num][0];
document.querySelector(".staticStep img").src[1] = images[num][1];
document.querySelector(".staticStep img").src[2] = images[num][2];
我也試過以下,但它給了我一個錯誤:
document.querySelector(".staticStep img")[0].src = images[num][0];
document.querySelector(".staticStep img")[1].src = images[num][1];
document.querySelector(".staticStep img")[2].src = images[num][2];
我在做什麼錯?
有道理,非常感謝! – mfroese