<head>
<script>
/**
* added by liu_xc 2004.6.23
* 移动select的部分内容,必须存在value,此函数以value为标准进行移动
*
* oSourceSel: 源列表框对象
* oTargetSel: 目的列表框对象
*/
function moveSelected(oSourceSel,oTargetSel)
{
//建立存储value和text的缓存数组
var arrSelValue = new Array();
var arrSelText = new Array();
//此数组存贮选中的options,以value来对应
var arrSelOption = new Array();
//存储源列表框中所有的数据到缓存中,并建立value和选中option的对应关系
for(var i=0; i<oSourceSel.options.length; i++)
{
if(oSourceSel.options[i].selected)
{
//存储
arrSelValue[arrSelValue.length] = oSourceSel.options[i].value;
arrSelText[arrSelText.length] = oSourceSel.options[i].text;
//建立value和选中option的对应关系
arrSelOption[arrSelOption.length] = oSourceSel.options[i];
}
}
//增加缓存的数据到目的列表框中,并删除源列表框中的对应项
for(var i=0; i<arrSelValue.length; i++)
{
//增加
var oOption = document.createElement("option");
oOption.text = arrSelText[i];
oOption.value = arrSelValue[i];
oTargetSel.add(oOption);
//删除源列表框中的对应项
oSourceSel.removeChild(arrSelOption[i]);
}
}
</script>
</head>
<body>
<select id='oSourceSel' ondblclick="moveSelected(document.all.oSourceSel,document.all.oTargetSel)" multiple>
<option>value1</option>
<option>value2</option>
</select>
<select id='oTargetSel' ondblclick="moveSelected(document.all.oTargetSel,document.all.oSourceSel)" multiple>
</select>
</body>