作用:双击左边的列表选项会增加到右边的列表
函数:
<script>
function addfruit(allfruit,selectfruit){
var allfruit = document.getElementById(allfruit);
var selectfruit = document.getElementById(selectfruit);
var removearr = new Array();
if(allfruit.options.selectedIndex<0){
alert("请选择一种水果");
return false;
}
var len = allfruit.options.length;
for(var i=0,j=0; i<len; i++){
if(allfruit.options[i].selected){
var newOption = document.createElement("option");
newOption.text = allfruit.options[i].text;
newOption.value = allfruit.options[i].value;
selectfruit.options.add(newOption);
removearr[j++] = i;
}
}
var dlen = removearr.length;
for(var i=0;i<dlen;i++){
allfruit.options.remove(removearr[i]-i);
}
}
</script>
html文档内容
<table>
<tr><td>所有水果列表</td><td>你喜欢的水果</td></tr>
<tr>
<td>
<select id="allfruit" multiple="multiple" size="4" οndblclick='javascript:addfruit("allfruit","selectfruit")'>
<option value="apple">苹果</option>
<option value="orange">橙子</option>
<option value="grape">葡萄</option>
</select>
</td>
<td>
<select id="selectfruit" multiple="multiple" size="4">
</select>
</td>
</tr>
</table>