获取所有选定元素选项的文本

Get the text of all select element options?

本文关键字:选项 文本 元素 获取      更新时间:2023-09-26

嗨,伙计们,我有这样的选择元素:

<select name='files'>
<option value='1'>logo.jpg</option>
<option value='2'>file.ex</option>
</select>

我想要这样的项目数组:

files=logo.jpg,file.ex(我想要文本而不是值!

谢谢。

var files = $('select[name="files"]').find("option").map(function() {
  return $(this).text();
}).get();

延伸阅读:

  • .map()方法
  • .get()方法