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.getElementsByTagName("option");
10
alert("" + y[x].text + " 是默认选项吗? " + y[x].defaultSelected);
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 selected="selected">Pineapple</option>
22
<option>Banana</option>
23
</select>
24
</form>
25
<button type="button" onclick="displayResult()">选中的是默认的水果吗?</button>
26
27
</body>
28
</html>