我正在尝试编写 js,以便我的选择选项下拉列表从我的数组中获取值和文本。js对我来说是新的。jsfiddle
我需要该值是数字和文本引号中的文本:
var locations = [
[23, 'Main Room'],
[1, 'Main Lobby'],
[2, 'Training Room'],
[56, 'Main Office'],
[57, 'Lower Office'],
[9, 'Lower Lobby'],
[62, 'Conference Room'],
[22, 'Outdoor Patio'],
[63, 'Upper Lobby']
];
var select = document.getElementById("selectRoom");
for(var i = 0; i < locations.length; i++) {
var opt = locations[i];
var el = document.createElement("option");
el.textContent = opt; // I just want the text within quotes from
el.value = opt; // I just want the number from opt
select.appendChild(el);
}
或者我的阵列应该是什么样子?位置= {“23”:“主房间”,“1”:“主大厅”};