【发布时间】:2015-10-21 06:21:35
【问题描述】:
我需要向下拉列表中添加选项。我在下拉列表中有一个包含我需要的选项的数组,但我不确定如何将数组附加到列表中
var productList = document.getElementById("selectFood");
var foodOption = document.createElement("option");
foodOption.textContent = [{
option1: "Meat Lovers"
}, {
option2: "Buffalo Wings"
}, {
option3: "margherita"
}, {
option4: "classic"
}];
for (i = 0; i < productList.length; i++) {
productList.appendChild(foodOption);
}
【问题讨论】:
-
textContent数组非常很奇怪。它是一个对象数组,其中每个对象都只有一个属性,并且这些属性都有不同的名称。如果你能改变它,我建议你改变它。
标签: javascript list drop-down-menu