<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Oo緣來是你oO


    posts - 120,comments - 125,trackbacks - 0

     【JavaScript】列表元素上下左右移動:Select和Option的應用

    馬嘉楠    2008-12-26

    共同學習,歡迎轉載。轉載請注明地址【http://blog.csdn.net/majianan/archive/2008/12/26/3614255.aspx】,謝謝O(∩_∩)O!

     

     

    功能如下:

    支持一次選中多項在左右列表中來回移動

     



    代碼如下:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     
    <HEAD>
      
    <TITLE> New Document </TITLE>
      
    <META NAME="Author" CONTENT="majianan">
      
    <script language="javascript" >
          
    var currentSel = null;
          
    function
     move(){
              
    if(arguments.length==1
    ){
                  moveUp(arguments[
    0
    ]);
              }
    else if(arguments.length==2
    ){
                  moveRight(arguments[
    0],arguments[1
    ]);
              }
          }
          
    function
     moveUp(direction){
              
    if(currentSel == nullreturn
    ;
              
    var index =
     currentSel.selectedIndex;
              
    if(direction){//up

                  if(index==0return;
                  
                  
    var value = currentSel.options[index-1
    ].value;
                  
    var text = currentSel.options[index-1
    ].text;
                  
                  currentSel.options[index
    -1].value =
     currentSel.options[index].value;
                  currentSel.options[index
    -1].text =
     currentSel.options[index].text;
                  
                  currentSel.options[index].value 
    =
     value;
                  currentSel.options[index].text 
    =
     text;
                  
                  currentSel.options[index].selected 
    = false
    ;
                  currentSel.options[index
    -1].selected = true
    ;
              }
    else{//down

                  if(index==(currentSel.length-1)) return;
                  
                  
    var value = currentSel.options[index+1
    ].value;
                  
    var text = currentSel.options[index+1
    ].text;
                  
                  currentSel.options[index
    +1].value =
     currentSel.options[index].value;
                  currentSel.options[index
    +1].text =
     currentSel.options[index].text;
                  
                  currentSel.options[index].value 
    =
     value;
                  currentSel.options[index].text 
    =
     text;
                  
                  currentSel.options[index].selected 
    = false
    ;
                  currentSel.options[index
    +1].selected = true
    ;
              }
          }
        
    function
     moveRight(src,des){
            
    if(src.selectedIndex==-1
    ){
                alert(
    "Please select first!"
    );
                
    return
    ;
            }
            
    for(var i=0;i<src.length;i++
    ){
                
    if
    (src[i].selected){
                    
    var op = document.createElement("option"
    );
                    op.value 
    =
     src.options[src.selectedIndex].value;
                    op.text 
    =
     src.options[src.selectedIndex].text;
                    des.options.add(op);
                        src.remove(i);
                        i
    --
    ;
                }
            }   
        }
        
    function
     setButton(obj){        
                
    if(obj.length==0return
    ;
                currentSel 
    =
     obj;
            
    if(obj.id=="leftSel"
    ){
                document.getElementById(
    "btnLeft").disabled = true
    ;
                    document.getElementById(
    "btnRight").disabled = false
    ;
                    
                    reSelect(document.getElementById(
    "rightSel"
    ));            
            }
    else
    {
                document.getElementById(
    "btnLeft").disabled = false
    ;
                document.getElementById(
    "btnRight").disabled = true
    ;    
                
                reSelect(document.getElementById(
    "leftSel"
    ));                
            }       
        }
        
        
    function
     reSelect(obj){
            
    for(var i=0; i<obj.length; i++
    ){
                
    if(obj[i].selected) obj[i].selected = false
    ;
            }
        }
        
    </script>

     
    </HEAD>

     
    <BODY>
      
    <form id="form1">
          
    <table width="40%" align="center">
              
    <tr>
                  
    <td>
                      
    <input type="button" value=" Up " id="btnUp" onClick="move(true);" style="width:65"/>
                    
    <br />
                    
    <input type="button" value=" Down " id="btnDowm" onClick="move(false);" style="width:65" />                
                  
    </td>

                  
    <td>
                      
    <select multiple id="leftSel" onclick="setButton(this)" ondblclick="document.getElementById('btnRight').click()" style="height:200px;width:100px;">
                        
    <optgroup label="Left List" /> 
                        
    <option value="1">Java</option>

                        
    <option value="2">JavaScript</option>
                        
    <option value="3">C++</option>
                        
    <option value="4">HTML</option>
                    
    </select>
                
    </td>
                
    <td>
                    
    <input type="button" value=" >> " id="btnRight" onClick="move(document.getElementById('leftSel'),document.getElementById('rightSel'));" style="width:65" />
                    
    <br />
                    
    <input type="button" value=" << " id="btnLeft" onClick="move(document.getElementById('rightSel'),document.getElementById('leftSel'));" style="width:65" />
                    
    </td>
                    
    <td>
                        
    <select multiple id="rightSel" onclick="setButton(this)"  ondblclick="document.getElementById('btnLeft').click()" style="height:200px;width:100px;" >
                        
    <optgroup label="Right List" /> 
                        
    <option value="5">CSS</option>

                        
    <option value="6">.Net</option>
                        
    </select>
                    
    </td>
                
    </tr>
            
    </table>
        
    </form>
     
    </BODY>
    </HTML>


    馬嘉楠
    jianan.ma@gmail.com

    posted on 2008-12-26 15:20 馬嘉楠 閱讀(2288) 評論(2)  編輯  收藏 所屬分類: SoureCode 、Java Script

    FeedBack:
    # re: 【原】【JavaScript】列表元素上下左右移動:Select和Option的應用[未登錄]
    2008-12-28 15:24 | chair
    還不錯,支持雙擊就更好了  回復  更多評論
      
    # re: 【原】【JavaScript】列表元素上下左右移動:Select和Option的應用
    2008-12-29 11:56 | 馬嘉楠
    @chair
    謝謝, 已經修改,支持雙擊操作  回復  更多評論
      
    主站蜘蛛池模板: 亚洲黄色免费在线观看| 91人人区免费区人人| 四虎影视永久免费观看地址| 亚洲熟女乱色一区二区三区| 男人的好看免费观看在线视频| 亚洲jjzzjjzz在线观看| 好男人www免费高清视频在线| 亚洲依依成人亚洲社区| 国产在线观看免费视频播放器| 国产一区二区三区亚洲综合| 五月天网站亚洲小说| 久久免费国产视频| 亚洲精品mv在线观看| 在线成人a毛片免费播放| 亚洲午夜福利AV一区二区无码| 亚洲国产成人91精品| 好男人视频社区精品免费| 亚洲精品人成网线在线播放va| 国产在线a不卡免费视频| av片在线观看永久免费| 亚洲AV无码一区二区二三区软件| 免费一级特黄特色大片| 亚洲成A∨人片在线观看不卡| 最近免费中文字幕大全免费版视频| 亚洲人成电影青青在线播放| 精品免费久久久久久成人影院| 一级做a爰片久久毛片免费陪 | 成全高清在线观看免费| 国产又粗又猛又爽又黄的免费视频| 日本一区二区三区在线视频观看免费| 亚洲综合色成在线播放| 四虎影视在线影院在线观看免费视频| 亚洲综合伊人制服丝袜美腿| 免费人妻无码不卡中文字幕18禁| 国内永久免费crm系统z在线| 亚洲sss综合天堂久久久| 亚洲中文字幕伊人久久无码| 91精品全国免费观看含羞草| 国产成人亚洲精品蜜芽影院| 久久综合日韩亚洲精品色| 日韩视频在线免费|