x
1
2
<html>
3
<head>
4
<meta charset="utf-8">
5
<title>蜜蜂教程(mifengjc.com)</title>
6
<script>
7
function displayResult() {
8
var x = document.getElementById("mySelect").selectedIndex;
9
var y = document.getElementById("mySelect").options;
10
alert("索引: " + y[x].index + " is " + y[x].text);
11
}
12
</script>
13
</head>
14
<body>
15
16
<form>
17
选择你最喜欢的水果:
18
<select id="mySelect">
19
<option>Apple</option>
20
<option>Orange</option>
21
<option>Pineapple</option>
22
<option>Banana</option>
23
</select>
24
</form>
25
<button type="button" onclick="displayResult()">显示索引</button>
26
27
</body>
28
</html>