티스토리 뷰

다음과 같이 간단합니다.

options[selectedIndex].id
-------------------

너무 많은 가정을하지 않고 (즉, select 는 유효한 SELECT 요소 임)

var options = select.options;
var id      = options[options.selectedIndex].id;
var value   = options[options.selectedIndex].value;

또는,

var options = select.options;
var value   = (options.selectedIndex != -1) ? options[selectedIndex].value : null;
var id      = (options.selectedIndex != -1) ? options[selectedIndex].id : null;

항상 허위 (또는 false로 평가되는 값)를 확인하십시오 . Ex 2는 변수를 null로 설정합니다 (선택된 항목이없는 경우).



출처
https://stackoverflow.com/questions/1904882
댓글
공지사항
Total
Today
Yesterday
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31