JavaScript获取选中项

chzhpo 2009-11-21 10:58:09
<script type="text/javascript">
function show(){
var ListUtil=new Object();
var ListUtil.getSelectedIndexes=function (oListbox){
var arrIndexes=new Array;
for(var i=0;i<oListbox.length;i++){
if(oListbox.options[i].selected){
arrIndexes.push[i];
}
}
return arrIndexes;
};
var oListbox=document.getElementById("selAge");
var arrIndexes=ListUtil.getSelectedIndexes(oListbox);
alert("There are"+arrIndexes.length+"option selected."+"The options have the indexes"+arrIndexes+".");
}
</script>
</head>

<body onload="show()">
<select name="selAge" id="selAge" size="3" multiple="multiple">
<option value="1" >18-21</option>
<option value="2" selected="selected">22-25</option>

<option value="3" selected="selected">26-29</option>
<option value="4">30-35</option>
<option value="5">Over 35</option>
</select>
</body>这段代码怎么报错missing:before statement和show
is not defined
...全文
53 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧