여기서 $('.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
반응형
'Front-End > jQuery' 카테고리의 다른 글
[jQuery] data() (0) | 2019.05.28 |
---|---|
[jQuery] on('click') & click Event (0) | 2019.05.28 |
[jQuery] jQuery Plugins 참고 사이트 (0) | 2019.05.23 |
[jQuery] checkbox relation 만들기 (dataset object concept) (0) | 2018.09.09 |
[jQuery] onchange() : 요소의 값이 변경될 때 발생 (0) | 2018.09.09 |
댓글