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]
相关文章推荐
- HTML DOM rowIndex 属性
- 关于select中的selectedIndex属性问题
- 动态创建html内容时所用的W3C DOM属性和方法
- HTML DOM innerheight、innerwidth 属性
- js -- dom -- js dom html节点的属性方法
- HTML DOM nodeType 属性
- JS的HTML DOM disabled 属性
- HTML DOM defaultValue 属性
- IE 混淆了 DOM 对象属性(property)及 HTML 标签属性(attribute),造成了对 setAttribute、getAttribute 的不正确实现
- HTML DOM nodeType 属性
- HTML DOM节点的属性获取
- CSS学习笔记06-分层(z-index属性).html
- HTML DOM margin 属性
- indexHtml部分属性
- html标签属性(attribute)和dom元素的属性(property)
- 在VSCode中编辑HTML文档时,在Dom标签上写style属性时智能提示的问题
- HTML DOM border 属性
- HTML DOM whiteSpace 属性
- HTML DOM overflow 属性(张艳冲的博客)