javascript列表框操作函数集合

 

<script language="javascript">

   

    /* 列表框互相操作函数集 */

 

  //描述: 添加不重复列表框元素

  function selAdd( srcList, dstList )

  {

      var selectedIndex = new Array();

      var count = 0;

 

      for ( i=0; i<srcList.options.length; i++ ){

 

         if ( srcList.options[i].selected ){

            

             selectedIndex[count] = i;

             count ++;

 

         }

     }                   

 

     for ( j=0; j<selectedIndex.length; j++ ){

        

         k = selectedIndex[j];

 

         if ( chkDup( srcList.options[k].value, dstList )==false ){

       &, nbsp;   dstList.options.length++;

             var len = dstList.options.length-1;

             dstList.options[len].value = srcList.options[k].value;

             dstList.options[len].text = srcList.options[k].text;

         }

 

     }

 

 }

 

 //描述: 删除列表框元素

 function selDel( list )

 {

     var len = list.options.length;

     var idx = 0;

 

     while ( idx< len ){

 

         if ( list.options[idx].selected ){

             list.options.remove(idx);

             len = list.options.length;

         }

         else{

             idx ++;

         }

     }

 }

 

 //描述: 检测列表框元素重复

 function chkDup( item, list )

 {

     for ( i=0; i<list.options.length; i++ ){

         //alert( item + " - " + list.options[i].value );

         if ( item == list.options[i].value ){

             return true;

         }

     }                   

     return false;

 }

 

 //描述: 选择列表框的全部成员

 function selSel( list, item )

 {

     item.value = " ";

     for ( i=0; i<list.options.length; i++ ){

         list.options[i].selected=true;

         item.value += list.options[i].value + " ";

     }

 

 }

 

 function selSelSingle( list, value )

 {

     for ( i=0; i<list.options.length; i++ ){

         if ( list.options[i].value == value ){

             list.options[i].selected=true;

             break;

         }

     }

 

 }

 //描述: 根据数组初始化列表框

 function selList( item, arr )

 {

 

     var curIndex, insIndex, val, text;

     var arrItem = new Array();

 

     if ( item ){

 

         item.length = 0;

         curIndex = 0;

 

        for ( i=0; i<arr.length; i++ ){

 

             item.length ++;

            insIndex = item.length - 1;

            

            if ( arr[i] ){

                arrItem = arr[i].split( ", " );

                text = arrItem[1];

                val  = arrItem[0];

                item.options[ insIndex ].text = text;   

                item.options[ insIndex ].value= val;

            }

        }

 

    }

}

 

    </script>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值