1. options Collection
option 배열은 드롭다운 리스트의 모든 option들의 배열을 반환한다.
각 <option> 태그의 시작은 0이다.
selectObject.options[]
option 배열은 드롭다운 리스트의 모든 option들의 배열을 반환한다.
각 <option> 태그의 시작은 0이다.
selectObject.options[]
<!-- 선택된 옵션의 인덱스와 텍스트 구하기 -->
<html>
<head>
<script type="text/javascript">
function getOptionIndex(){
var x = document.getElementById('mySelect')
alert(x.selectedIndex)
}
function getOption(){
var x = document.getElementById('mySelect')
alert(x.options[x.selectedIndex].text)
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br />
<input type="button" onclick="getOptionIndex()" value="Alert Option Index"><br />
<input type="button" onclick="getOption()" value="Alert Selected Fluit">
</body>
</html>
<html>
<head>
<script type="text/javascript">
function getOptionIndex(){
var x = document.getElementById('mySelect')
alert(x.selectedIndex)
}
function getOption(){
var x = document.getElementById('mySelect')
alert(x.options[x.selectedIndex].text)
}
</script>
</head>
<body>
<form>
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<br />
<input type="button" onclick="getOptionIndex()" value="Alert Option Index"><br />
<input type="button" onclick="getOption()" value="Alert Selected Fluit">
</body>
</html>
WRITTEN BY
- 손가락귀신
정신 못차리면, 벌 받는다.
,