728x90
제이쿼리(jQuery)로 select box(셀렉트 박스) 값 가져오기
<select id="myselect" onchange="selectTest();">
<option value="1">일번</option>
<option value="2">이번</option>
<option value="3">삼번</option>
<option value="4">사번r</option>
<option value="5">오번</option>
</select>
<script>
function selectTest(){
var testA = $("#myselect > option:selected").val(); //선택된 옵션의 value 가져오기
console.log(testA);
var testB = $( "#myselect option:selected" ).text(); //선택된 옵션의 text 가져오기
console.log(testB);
}
</script>
728x90
'프로그래밍 > jQuery' 카테고리의 다른 글
[jQuery(제이쿼리)] Object의 특정 클래스(Class) 포함 여부 확인 (0) | 2020.04.12 |
---|---|
[jQuery(제이쿼리)] 선택자에 변수 넣기 (0) | 2020.04.12 |
[jQuery(제이쿼리)] 형제 요소의 탐색 .siblings() .next() .prev() (0) | 2020.04.12 |
[jQuery(제이쿼리)] table td 또는 ul li 값 가져오기 (0) | 2020.04.12 |
제이쿼리(jQuery)로 select box 값 고정하기/ 변경하기 (0) | 2020.03.31 |