下面是代碼:添加變量HREF在「for」循環
for (i = 0; i < 8; i++) {
var meun = document.createElement("div");
meun.setAttribute('id', i);
meun.setAttribute("style", "width:70px; height:70px; background:url(archive/" + i + ".jpg); background-size: 70px 70px; float:left; margin-top:10px; opacity:1");
document.body.appendChild(frame);
document.getElementById("frame").appendChild(meun);
meun.addEventListener('click', function() {
window.location.href = "i+'.html'"
}, false);
}
我的問題是,在addEventListener
:如何通過可變i
到href
?我想這是一個語法問題。
最好避免使用開始用數字和數字是,使用字母標識或下劃線代替,同爲類) – dmi3y