반응형
jQuery를 사용해서 select에서 선택된 값을 가지고 오는 방법은 아래와 같습니다.
$('.target-selection').click(function(){
var option_value = $(".target-selection option:selected").val();
var option_text = $(".target-selection option:selected").text();
console.log(option_value );
console.log(option_text );
});
target-selection 이라는 클래스를 가진 select 에서 선택이 이루어지면
option:selected를 활용해서 value값은 val() 로 가지고 오고요. text 값은 text()로 가지고 옵니다.
이렇게 가지고 온 값을 가지고 후속 처리를 해주면 되겠죠??
간단하지만 계속 까먹는 select 선택된 값 가지고 오기를 정리해봤습니다. 끝 :-)
반응형
'자바스크립트,부트' 카테고리의 다른 글
html select selection for test / jQuery, trigger (0) | 2019.05.31 |
---|---|
자바스크립트 jQuery input enter event (0) | 2019.05.31 |
datatables redraw (0) | 2019.05.31 |
jQuery로 select 된 값 가지고 오기 (0) | 2019.05.27 |
javascript - select - focus and change (0) | 2019.05.26 |
IE11, Edge 에서 CSS 배경이미지 SVG 사용 (0) | 2018.01.19 |
자바스크립트 URL 정보 가져오기(찾기, 확인) (0) | 2017.06.15 |
jQuery를 활용해서 클래스(class) add / remove 하기 (0) | 2017.06.09 |