我有GET问题多所有选择的选项中选择如何获得所有选择的选项的文本形式多选择使用JavaScript
<select multiple="" title="" class="" id="fm_delivery_or_collection" name="fm_fields[fm_delivery_or_collection][]">
<option value="90">Delivery or Collection1</option>
<option value="91">Delivery or Collection2</option>
<option value="92">Delivery or Collection3</option>
</select>
贝娄是我的代码和它返回我只有第一个选择的选项
var select = form.find('select')
for (var i = 0; i < select.length; i++)
{
var s_id = jQuery(select[i]).attr('id');
var str="",i;
var e = document.getElementById(s_id);
var strUser = e.options[e.selectedIndex].text;
var name = jQuery(select[i]).attr('name')
var str1 = jQuery(select[i]).attr('id').replace("fm_"," ")
requestString += "<b>"+str1.replace(/_/g," ")+"</b>" + ':' +strUser+"<br>";
}
所以请建议我如何获取所有选定的选项文本和我犯的错误?
的价值'选择multiple'(或'选择[select.selectedIndex]')是一个数组... – Teemu 2013-02-20 05:15:16
答案过于复杂。您可以使用.map()获取所有选定的选项文本。 $(“select:selected”)。map(function(i,element){return jQuery(element).text();})。get();' – 2018-01-30 10:08:05