1.html代码如下:
<html>
<head>
</head>
<body>
<form name="form1" id="form1">
Select your favorite fruit:
<select id="mySelect" name="mySelect">
<option value="11">Apple</option>
<option value="22" >Orange</option>
<option value="33">Pineapple</option>
<option value="44">Banana</option>
</select>
<br /><br />
<input type="button" onclick="getIndex()"
value="Alert index of selected option">
</form>
</body>
</html>

 2.javascript代码如下:

<script type="text/javascript">
function getIndex()
{
  //从document对象中,获取select标签
  var a=document.getElementById("mySelect");
  //select标签获取的值其实是一个数组--a.options[]; 然后,选定项的下标是--a.selectedIndex
   var b=a.options[a.selectedIndex].value;   
   alert(b); 
} 
</script>

  



作者:木木

博客里的文章,来自笔者在读书与工作过程中的论文阅读笔记、实验笔记、读书笔记、工作技术笔记,还有一些来自网文收藏。也许不定期还会写一些伤春悲秋的无用之文。关于技术方面写的一些随笔,仅供各位读者参考,写下来是对当时的自己有益,再过一段时间,或再过几年,不一定对其他人还有用。文章版权方面的:躺在这里的无用之文,未经授权不要转载。