JavaScript:两个可以互相交换数据的列表框

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">    
    <html>    
      <head>    
        <title>addMulitOptions.html</title>    
            
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">    
        <meta http-equiv="description" content="this is my page">    
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">    
        <script type="text/javascript">   
            // 移动id为from的列表中的选中项到id为to的列表中  
            function move(from,to) {    
                // 获取移动源  
                var fromBox = document.getElementById(from);    
                // 获取移动目的地  
                var toBox = document.getElementById(to);  
                // 当移动源存在选中项时  
                while(fromBox.selectedIndex != -1){  
                    // 将移动源中的选中项添加到移动目的地的末尾  
                    toBox.appendChild(fromBox.options[fromBox.selectedIndex]);  
                }  
            }    
      
            // 移动id为from的列表中的所有项到id为to的列表中  
            function moveAll(from,to) {    
                // 获取移动源  
                var fromBox = document.getElementById(from);    
                // 获取移动目的地  
                var toBox = document.getElementById(to);  
                // 当移动源存在选中项时  
                while(fromBox.options.length > 0){  
                    // 将移动源中的选中项添加到移动目的地的末尾  
                    toBox.appendChild(fromBox.options[0]);  
                }  
            }    
        </script>    
      </head>    
          
      <body>    
        <select id="leftBox" multiple="multiple" style="height: 200px; width: 100px;">    
            <option value="1">a</option>    
            <option value="2">b</option>    
            <option value="3">c</option>    
            <option value="4">d</option>    
        </select>    
        <input type="button" value=">" οnclick="move('leftBox','rightBox')"/>    
        <input type="button" value="<" οnclick="move('rightBox','leftBox')"/>    
        <input type="button" value=">>" οnclick="moveAll('leftBox','rightBox')"/>    
        <input type="button" value="<<" οnclick="moveAll('rightBox','leftBox')"/>    
        <select id="rightBox" multiple="multiple" style="height: 200px; width: 100px;">    
            <option value="11">A</option>    
            <option value="22">B</option>    
            <option value="33">C</option>    
            <option value="44">D</option>    
        </select>    
      </body>    
    </html>  

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值