当前位置: 首页 > 网络学院 > 客户端脚本教程 > HTML DOM > HTML DOM selectedIndex 属性

HTML DOM
DOM TableRow 对象
DOM Textarea 对象
DOM Window 对象

HTML DOM selectedIndex 属性


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 368 ::
收藏到网摘: n/a

Definition and Usage
定义与用法

The selectedIndex property sets or returns the index of the selected option in a drop-down list.
selectedIndex 属性可设置或返回下拉列表中选中项的index值

Note: If the dropdown list allows for multiple selections it will only return the index of the first option selected.
注意:如果下拉列表可进行多项的选择,那么只会返回出第一个被选中的项目index值

Syntax 语法

selectObject.selectedIndex=number


Example 举例

<html>
<head>
<script type="text/javascript">
function getOptionIndex()
{
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="getOptionIndex()"
value="Alert index of selected fruit">
</form>
</body>
</html>


演练

Alert the index of the selected option in a dropdown list
提示下拉列表里被选中项目的index值

Alert the text of the selected option in a dropdown list
提示下拉列表中被选中项目的文字

Change the text of the selected option
改变选中项目的文字

Remove options from a dropdown list
从下拉列表中删除可选项

评论 (0) All

登陆 | 还没注册?