案例:javascript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
function alertValue()
5
  {
6
  var x=document.getElementById("mySelect").selectedIndex;
7
  alert(document.getElementsByTagName("option")[x].value);
8
  }
9
</script>
10
</head>
11
<body>
12
13
<form>
14
Select your favorite fruit:
15
<select id="mySelect">
16
  <option value="apple">Apple</option>
17
  <option value="orange">Orange</option>
18
  <option value="pineapple">Pineapple</option>
19
  <option value="banana">Banana</option>
20
</select>
21
<br /><br />
22
<input type="button" onclick="alertValue()" value="Alert selected value">
23
</form>
24
25
</body>
26
</html>
27