我正在尝试创建二维数组并使用它填充下拉列表。
但我收到了Uncaught SyntaxError: Unexpected string error。
var cuisines = ["001","Australian"],["002","American"];
var sel = document.getElementById('CuisineList');
for(var i = 0; i < cuisines.length; i++) {
var opt = document.createElement('option');
opt.innerHTML = cuisines[i][1];
opt.value = cuisines[i][0];
sel.appendChild(opt);
}
<select id="CuisineList"></select>
请帮我。谢谢。
定义二维数组时需要外括号。
var cuisines = [["001","Australian"],["002","American"]];
此外,看起来您正在使用字母“o”而不是数字 0 作为您的索引之一。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句