日期:2014-05-20  浏览次数:20529 次

高手帮忙改改这段JS,想实现多条被选中的TEXT一起移到右边
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,请问上面的JS要怎么改,才能实现被选中的几条数据一起移过去?

------解决方案--------------------
如果你需要移动多个,使用下面的函数就可以了。
在SelectionMode为Multiple的时候,
selectedIndex的值是被选择中项的最小项下标值。


function SelectFieldMore()
{
var lst1=window.document.getElementById( "ListBoxLeft ");
do
{
SelectField();
}while(lst1.selectedIndex > 0);
}