你能帮我调试下面的代码吗?这是一个JavaScript交换两个列表框之间的列表项。仅在IE8中,它给出了错误:“options.length为null或不是对象”
<script>
function listbox_moveacross(sourceID,destID){
var src=document.getElementById(sourceID);
var dest=document.getElementById(destID);
for(var count=0;count<src.options.length;count++){
if(src.options[count].selected==true){
var option=src.options[count];
var newOption=document.createElement("option");
newOption.value=option.value;newOption.text=option.text;
newOption.selected=true;
try{dest.add(newOption,null);
src.remove(count,null);
}
catch(error){
dest.add(newOption);
src.remove(count);
}
count--;
}
}
}
</script>
<!-- Source listbox-->
<select name="list1" id="list1" multiple="multiple" style="height:120px;" ondblclick="listbox_moveacross('list1', 'selectedlist1')">
<option>Please Select...</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
<option>Option 6</option>
</select>
<a href="#" onclick="listbox_moveacross('list1', 'selectedlist1')">Add ></a>
<br/>
<a href="#" onclick="listbox_moveacross('selectedlist1', 'list1')">< Remove</a>
<!-- Destination listbox -->
<select id="selectedlist1" name="selectedlist1" multiple size="7" style="width:150px;" ondblclick="listbox_moveacross('selectedlist1', 'list1')"></select>