私は誰もがについて投稿したことだろうvalueとtextオプションから取得する<option>と、誰も提案しませんlabel。
だから私labelも提案しています、すべてのブラウザでサポートされています
取得するvalue(他の人が提案したのと同じ)
function test(a) {
var x = a.options[a.selectedIndex].value;
alert(x);
}
取得するにはoption text(つまり、コミュニケーションまたは-選択-)
function test(a) {
var x = a.options[a.selectedIndex].text;
alert(x);
}
または (新しい提案)
function test(a) {
var x = a.options[a.selectedIndex].label;
alert(x);
}
HTML
<select onchange="test(this)" id="select_id">
<option value="0">-Select-</option>
<option value="1">Communication</option>
<option value="2" label=‘newText’>Communication</option>
</select>
注:上記のHTMLのoption値2では、CommunicationではなくnewTextlabelが返されます
また
注:Firefoxでlabelプロパティを設定することはできません(returnのみ)。