日期:2014-05-16  浏览次数:20365 次

如何通过javascript将listbox中的项全部选中??
我有一个listbox,已经设置为可以多选了,但是现在不知道怎么通过javascript来选中其所有项,(因为不选中的话,该listbox传的值会为空)

我使用下面这个方法,虽然不报错,但是没有反应;
function   selectall(){
var   i;

for   (i=0;i <=document.getElementById( "simpledistrict ").options.length;i++){
document.getElementById( "simpledistrict ").SelectedIndex=i;    
}
}

------解决方案--------------------
for (vari=0;i <=document.getElementById( "simpledistrict ").options.length;i++)
{
document.getElementById( "simpledistrict ").options[i].selected = true;
}