반응형
// 셀렉트 박스 옵션 사이에 있는 텍스트 값을 가져온다.
options[target.seletedIndex].text
// 셀렉트 박스 value 의 값을 가져온다.
options[target.selectedIndex].value
예제
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<select name="selectBox" id="selectBox">
<option value="가" selected>A</option>
<option value="나">B</option>
<option value="다">C</option>
</select>
</body>
<script type="text/javascript">
var target = document.getElementById("selectBox");
alert('선택된 옵션 text 값=' + target.option[target.selectedIndex].text); // 옵션 text 값
alert('선택된 옵션 vlaue 값=' + target.options[target.selectedIndex].value); // 옵션 value 값
</script>
</html>
예제 결과화면
반응형
'Programming > JavaScript' 카테고리의 다른 글
[javascript] object 내용 확인하기 (0) | 2022.08.07 |
---|---|
[jQuery] .ready 와 .onload의 차이점 (0) | 2021.11.18 |
[javascript] 공백, 특수문자 체크하기 (0) | 2021.11.11 |
[jQuery] DataTable을 그린 후에 작업 수행할 때. (0) | 2021.11.09 |
[jQuery] 보이기, 숨기기 (0) | 2021.11.08 |