首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

高手帮忙改改这段JS,想实现多条被选中的TEXT一起移到右边,该如何解决

2012-01-21 
高手帮忙改改这段JS,想实现多条被选中的TEXT一起移到右边functionTest(lbFieldsSelect,value){for(j0j

高手帮忙改改这段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);
}

热点排行