您的位置:首页 > Web前端 > HTML

HTML DOM selectedIndex 属性

2011-12-11 21:49 375 查看

定义和用法

selectedIndex 属性可设置或返回下拉列表中被选选项的索引号。

注释:若允许多重选择,则仅会返回第一个被选选项的索引号。

语法

selectObject.selectedIndex=number


实例

下面的例子可提示出被选选项的索引号:

<html>
<head>
<script type="text/javascript">
function getIndex()
{
var x=document.getElementById("mySelect")
alert([code]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>[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: