Last active
December 1, 2017 08:05
-
-
Save TomckySan/9579976 to your computer and use it in GitHub Desktop.
【jQuery】セレクトボックスの選択要素を抽出 ref: http://qiita.com/tomcky/items/8f1868f1fb963732de39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select name='alphabet' multiple='multiple'> | |
<option value='ABC'>えーびーしー</option> | |
<option value='DEF'>でーいーえふ</option> | |
<option value='GHI'>じーえいちあい</option> | |
<option value='JKL'>じぇーけーえる</option> | |
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 複数選択された表示文字列を配列として取得 | |
$('[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