找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 4767|回复: 0

[ASP] 获取所有select mutiple的值--javascript

[复制链接]

1214

主题

352

回帖

11

精华

管理员

菜鸟

积分
93755

贡献奖关注奖人气王精英奖乐于助人勋章

发表于 2011-4-6 16:37:02 | 显示全部楼层 |阅读模式
function  Create(SourceSelect,TargetSelect)  
{  
       var  IsCreate  =  true;  
       var  theIndex    =  SourceSelect.selectedIndex;  
       var  theLength  =  SourceSelect.length  ;  
       if  (theIndex  ==  -1  )  //如果源Select为空的话,则退出过程  
        return  false;  
       while  (IsCreate)          //添加到目的Select循环  
       {  
               theValue  =  SourceSelect.options[theIndex].text;    //得到所选择的文本  
            
               TargetSelect.options.add(new  Option(theValue));    //目的Select增加一个文本  
           
               theIndex  =  theIndex  +  1;      //如果是选择多列的话,对下一个进行处理  
                 
               if  (theIndex  ==  theLength)  //theLength  如果是4的话,则theIndex应该是3,  
               {                                                    //如果两者想等的话,则源Select多了一个值,  
                       IsCreate  =  false;            //所以需要退出循环  
                       break;  
               }  
               if  (SourceSelect.options[theIndex].selected  ==  false)//如果没有被选择的话,则退出循环  
               {  
                       IsCreate  =  false;  
               }  
       }         
         
       while  (IsCreate  ==  false)                                    //删除源select循环  
       {  
             SecIndex    =  SourceSelect.selectedIndex;  //动态得到被选择的索引  
             theLength  =  SourceSelect.length  ;              //动态得到Select的长度  
             SourceSelect.remove(SecIndex);                    //删除指定索引的元素  
             if  (theLength  ==  1)                                          //表示最后一个元素已删除,  
                     return  false;                                              //源select空了,退出循环  
             if  (theLength  ==  SecIndex  +  1)                    //表示多选的已全部删掉,退出循环  
                     return  false;  
             if  (SourceSelect.options[SecIndex].selected  ==  false)  
             {  
                     IsCreate  =  true;  
             }  
       }  
}

【VB】QQ群:1422505加的请打上VB好友
【易语言】QQ群:9531809  或 177048
【FOXPRO】QQ群:6580324  或 33659603
【C/C++/VC】QQ群:3777552
【NiceBasic】QQ群:3703755
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表