본문 바로가기
Front-End/jQuery

[jQuery] select option 설정

by 김뚱 2019. 5. 27.

여기서 $('.select-test')는 select를 가리킨다.

 

- index로 option에 접근하여 selected 설정하기

$('.select-test > option:eq(0)').prop('selected', true);
$('.select-test > option:eq(0)').attr('selected', 'selected');

 

- value값으로 option에 selected 설정하기

$('.select-test').val('test');
$('.select-test > option[value="test"]').attr('selected', true);
$('.select-test > option[value="test"]').prop('selected', 'selected');

 

 

Reference

https://oingbong.tistory.com/175

 

jquery - select option 선택값 가져오기

[jquery] select box 선택값 가져오기 // select box ID로 접근하여 선택된 값 읽기 $("#셀렉트박스ID option:selected").val(); // select box Name로 접근하여 선택된 값 읽기 $("select[name=셀렉트박스name]")..

oingbong.tistory.com

https://snowple.tistory.com/379

 

[jQuery] jQuery Select Box 제어하기

출처: http://blog.daum.net/twinsnow/124 jQuery로 선택된 값 읽기 $("#selectBox option:selected").val(); $("#select_box > option:selected").val() $("select[name=name]").val(); jQuery로 선택된 내용 읽..

snowple.tistory.com

 

728x90
반응형

댓글