我有3个下降,但它可以改变。它是动态下拉
如何在这些下拉列表中获取所有选定的值?
答案 0 :(得分:2)
这是我的评论的解释.. 运行代码段以检查其运行情况
var combos = document.querySelectorAll('[name^="select"]');
function getvalues() {
// Clear shown data
console.clear();
for (var i=0; i < combos.length; i++) {
// Get selected option value
var option = combos[i].options[combos[i].selectedIndex];
// Show options
console.log(combos[i].name + " :: " + option.value + " : " + option.text);
}
}
<select name="select-1">
<option value="1" selected>First</option>
<option value="2">Second</option>
<option value="3">Third</option>
</select>
<select name="select-2">
<option value="1">First</option>
<option value="2" selected>Second</option>
<option value="3">Third</option>
</select>
<select name="select-3">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3" selected>Third</option>
</select>
<button onclick="getvalues()">Get values</button>