function Test( lbFieldsSelect,value)
{
for (j = 0;j <lbFieldsSelect.length; j++)
{
if (lbFieldsSelect.options[j].value == value) return true;
}
return false;
}
function SelectField()
{
var lst1=window.document.getElementById( "ListBoxLeft ");
var lstindex=lst1.selectedIndex;
if(lstindex <0)
return;
var v = lst1.options[lstindex].value;
var t = lst1.options[lstindex].text;
var lst2=window.document.getElementById( "ListBoxRight ");
if (Test(lst2,v)){
return;
}
lst2.options[lst2.options.length] = new Option(t,v,true,true);
lst1.options[lstindex].parentNode.removeChild(lst1.options[lstindex]);
}
上面实现了一条数据的从左到右移动,
我现在把SelectionMode模式改为Multiple,请问要怎么改,才能实现被选中的几条数据一起移过去?
------解决方案--------------------------------------------------------
<select id= "source_sel " multiple>
<option value=1> 1 </option>
<option value=2> 2 </option>
<option value=3> 3 </option>
<option value=4> 4 </option>
<option value=5> 5 </option>
</select>
<select id= "dest_sel ">
</select>
<input type= "button " id= "btn1 " value= "Move " onclick= "MoveItems() ">
<script>
function MoveItems()
{
var selObj = document.getElementById( 'source_sel ');
var destObj = document.getElementById( 'dest_sel ');
var i;
for (i=0; i <selObj.options.length; i++) {
if (selObj.options[i].selected) {
destObj.options[destObj.options.length] = new Option(selObj.options[i].value,selObj.options[i].text,true,true);
selObj.options[i].parentNode.removeChild(selObj.options[i]);
i--;
}
}
}
</script>
写个简单的例子