中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

Select options 集合

Select 對象參考手冊 Select 對象

定義和用法

option 集合可返回包含 <select> 元素中所有 <option> 的一個數(shù)組。

注意: 數(shù)組中的每個元素對應(yīng)一個 <option> 標(biāo)簽 - 由 0 起始。

語法

selectObject.options

屬性

屬性 描述
length 返回集合的option元素數(shù)目
selectedIndex 設(shè)置或者返回select對象已選選項的索引值。(以 0 起始)

方法

方法 描述
[index] 以數(shù)字形式指定元素索引 (以 0 開始)
[add(element[,index])] 在集合中添加option元素
item(index) 以數(shù)字索引返回集合中元素
namedItem(name) 以名稱為索引返回集合元素
remove(index) 從集合中移除元素

瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要瀏覽器都支持 options 集合


實例

實例

循環(huán)輸出下拉列表中的所有選項:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>小白教程(json.cn)</title>
<script>
function displayResult(){
????var x=document.getElementById("mySelect");
????var txt="All options: ";
????var i;
????for (i=0;i<x.length;i++){
????????txt=txt + "n" + x.options[i].text;
????}
????alert(txt);
}
</script>
</head>
<body>

<form>
你最喜歡的水果:
<select id="mySelect">
????<option>Apple</option>
????<option>Orange</option>
????<option>Pineapple</option>
????<option>Banana</option>
</select>
</form>
<button type="button" onclick="displayResult()">顯示所有選項的文本</button>

</body>
</html>

運行代碼 ?

實例s

更多實例

通過另外一個下拉菜單已選選項來修改當(dāng)前下拉菜單的選項。


Select 對象參考手冊 Select 對象其他擴(kuò)展