使用此代码:
$('#select-from').each(function() {
alert($(this).val());
});
<select name="selectfrom" id="select-from" multiple="" size="15">
<option value="1">Porta iPhone Auto</option>
<option value="2">Leather Moto Vest</option
</select>
我从该选择框中获取所有已选择的值,如何获取未选择的值?
最佳答案
尝试以下
获取所有值
var valuesArray = $("#select-from option").map(function(){
return this.value;
}).get();
获取不同数组中选定和未选定的值。
var values = {
selected: [],
unselected:[]
};
$("#select-from option").each(function(){
values[this.selected ? 'selected' : 'unselected'].push(this.value);
});
谢谢
湿婆
关于javascript - 从选择框中获取所有选项(选定和未选定),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16731924/