나는 모든 사람에 대해 올렸습니다 궁금해 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>
참고 : option값 2에 대한 위의 HTML 에서 Communication 대신 newText 를 label반환합니다.
또한
참고 : Firefox에서는 레이블 속성을 설정할 수 없습니다 (반환 만 가능).