我正在尝试使用 Javascript 在 ul 中制作音乐专辑的动态列表
var heavyArtillery = new Album("Heavy Artillery","Arkasia","2011");
var antenna = new Album("Antenna","Sonic Youth","2012");
albumList = new Array(heavyArtillery,antenna);
var albumLi;
var ul = document.getElementById("albumlist");
for(var i=0; i<albumList.length; i=i+1)
{
albumLi = document.createElement('li');
albumLi.innerHTML = ""+albumList[i].album;
//ul.appendChild(albumLi);
alert(i);
}
如果我从 appendChild 行中获取注释,则 alert(i) 甚至不会显示。为什么它不能正常工作?这是 HTML 片段:
<div data-theme="a" data-role="header">
<h3>
Albums
</h3>
</div>
<ul id="albumlist">
</ul>