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");
9
var txt = "All options: ";
10
var i;
11
for (i = 0; i < x.length; i++) {
12
txt = txt + "
13
" + x.options[i].text;
14
}
15
alert(txt);
16
}
17
</script>
18
</head>
19
<body>
20
21
<form>
22
你最喜欢的水果:
23
<select id="mySelect">
24
<option>Apple</option>
25
<option>Orange</option>
26
<option>Pineapple</option>
27
<option>Banana</option>
28
</select>
29
</form>
30
<button type="button" onclick="displayResult()">显示所有选项的文本</button>
31
32
</body>
33
</html>