本文实例讲述了JS显示下拉列表框内全部元素的方法。分享给大家供大家参考。具体如下:
下面的JS代码可以通过alert框显示指定下拉列表的全部元素
<!DOCTYPE html>
<html>
<head>
<script>
function getOptions()
{
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 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="getOptions()"
value="Output all options">
</form>
</body>
</html>
更多信息请查看IT技术专栏