首页 > 语言 > JavaScript > 正文

javascript列表框操作函数集合汇总

2024-05-06 14:32:49
字体:
来源:转载
供稿:网友
代码如下:
<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;
         }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选