Skip to content

Instantly share code, notes, and snippets.

@TomckySan
Last active December 1, 2017 08:05
Show Gist options
  • Save TomckySan/9579976 to your computer and use it in GitHub Desktop.
Save TomckySan/9579976 to your computer and use it in GitHub Desktop.
【jQuery】セレクトボックスの選択要素を抽出 ref: http://qiita.com/tomcky/items/8f1868f1fb963732de39
<select name='alphabet' multiple='multiple'>
<option value='ABC'>えーびーしー</option>
<option value='DEF'>でーいーえふ</option>
<option value='GHI'>じーえいちあい</option>
<option value='JKL'>じぇーけーえる</option>
</select>
// 複数選択された表示文字列を配列として取得
$('[name=alphabet]').change(function() {
var array = [];
$('[name=alphabet] option:selected').each(function() {
array.push($(this).text());
});
console.log(array); // 出力:["えーびーしー", "でーいーえふ"]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment