HTML DOM selectedIndex ÊôÐÔ

¶¨ÒåºÍÓ÷¨

selectedIndex ÊôÐÔ¿ÉÉèÖûò·µ»ØÏÂÀ­ÁбíÖб»Ñ¡Ñ¡ÏîµÄË÷ÒýºÅ¡£

×¢ÊÍ£ºÈôÔÊÐí¶àÖØÑ¡Ôñ£¬Ôò½ö»á·µ»ØµÚÒ»¸ö±»Ñ¡Ñ¡ÏîµÄË÷ÒýºÅ¡£

Óï·¨

selectObject.selectedIndex=number

ʵÀý

ÏÂÃæµÄÀý×Ó¿ÉÌáʾ³ö±»Ñ¡Ñ¡ÏîµÄË÷ÒýºÅ£º

<html>
<head>
<script type="text/javascript">
function getIndex()
  {
  var x=document.getElementById("mySelect")
  alert(x.selectedIndex)
  }
</script>
</head>
<body>

<form>
Select your favorite fruit:
<select id="mySelect">
  <option>Apple</option>
  <option>Orange</option>
  <option>Pineapple</option>
  <option>Banana</option>
</select>
<br /><br />
<input type="button" onclick="getIndex()"
value="Alert index of selected option">
</form>

</body>
</html>
VUE