1
我想用對象數據中的字符串來填充這個列表。它出現爲'未定義'。這是對數據對象的引用不起作用。爲什麼?爲什麼此對象引用不起作用?
JS
data = [
{"q":"How much?", "ac":"20%", "a1": "1%", "a2": "10%", "a3": "5%"},
{"q":"What", "ac":"Ball", "a1": "Stone", "a2": "Bierd", "a3": "Carl"},
{"q":"When?", "ac":"1999", "a1": "2000", "a2": "2001", "a3": "2002"}
];
var q=0
window.onload = function() {
var ids =['a','b','c','d'];
var ans =['a1','a2','a3','ac'];
for (var j=0; j < ids.length; j++) {
var a = ans[j];
document.getElementsByClassName(ids[j])[0].innerHTML = data[q].a; //[<-- PROBLEM HERE]
};
}
HTML
<ul class="answers_quiz">
<li class="a"></li>
<li class="b"></li>
<li class="c"></li>
<li class="d"></li>
</ul>
優秀!謝謝 – jenswirf 2012-02-02 12:40:28
沒問題,很高興我可以幫忙:) – 2012-02-02 12:42:36