jquery select 上移下移

  1. <!--jQuery插件---MultiSelects(左右选框),支持select下option元素的上移下移  
  2. 源码:-->  
  3.   
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head>  
  7. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  8. <title>MultiSelects(左右选框) 完美版</title>  
  9. <script src="http://demo.deeka.cn/limit2checked/jquery-1.2.6.pack.js"></script>  
  10. <script>  
  11. <!--  
  12. $(function(){  
  13.    $("#s1 option:first,#s2 option:first").attr("selected",true);  
  14.     
  15.    $("#s1").dblclick(function(){  
  16.      var alloptions = $("#s1 option");  
  17.      var so = $("#s1 option:selected");  
  18.   
  19.      so.get(so.length-1).index == alloptions.length-1?so.prev().attr("selected",true):so.next().attr("selected",true);  
  20.       
  21.      $("#s2").append(so);  
  22.    });  
  23.     
  24.    $("#s2").dblclick(function(){  
  25.      var alloptions = $("#s2 option");  
  26.      var so = $("#s2 option:selected");  
  27.       
  28.      so.get(so.length-1).index == alloptions.length-1?so.prev().attr("selected",true):so.next().attr("selected",true);  
  29.       
  30.      $("#s1").append(so);  
  31.    });  
  32.     
  33.    $("#add").click(function(){  
  34.      var alloptions = $("#s1 option");  
  35.      var so = $("#s1 option:selected");  
  36.   
  37.      so.get(so.length-1).index == alloptions.length-1?so.prev().attr("selected",true):so.next().attr("selected",true);  
  38.       
  39.      $("#s2").append(so);  
  40.    });  
  41.     
  42.    $("#remove").click(function(){  
  43.      var alloptions = $("#s2 option");  
  44.      var so = $("#s2 option:selected");  
  45.       
  46.      so.get(so.length-1).index == alloptions.length-1?so.prev().attr("selected",true):so.next().attr("selected",true);  
  47.       
  48.      $("#s1").append(so);  
  49.    });  
  50.     
  51.    $("#addall").click(function(){  
  52.      $("#s2").append($("#s1 option").attr("selected",true));  
  53.    });  
  54.     
  55.    $("#removeall").click(function(){  
  56.      $("#s1").append($("#s2 option").attr("selected",true));  
  57.    });  
  58.     
  59.    $("#s1up").click(function(){  
  60.      var so = $("#s1 option:selected");  
  61.      if(so.get(0).index!=0){  
  62.        so.each(function(){  
  63.            $(this).prev().before($(this));  
  64.        });  
  65.      }  
  66.    });  
  67.     
  68.    $("#s1down").click(function(){  
  69.      var alloptions = $("#s1 option");  
  70.      var so = $("#s1 option:selected");  
  71.       
  72.      if(so.get(so.length-1).index!=alloptions.length-1){  
  73.        for(i=so.length-1;i>=0;i--)  
  74.        {  
  75.          var item = $(so.get(i));  
  76.          item.insertAfter(item.next());  
  77.        }  
  78.      }  
  79.    });  
  80.     
  81.    $("#s2up").click(function(){  
  82.      var so = $("#s2 option:selected");  
  83.      if(so.get(0).index!=0){  
  84.        so.each(function(){  
  85.            $(this).prev().before($(this));  
  86.        });  
  87.      }  
  88.    });  
  89.     
  90.    $("#s2down").click(function(){  
  91.      var alloptions = $("#s2 option");  
  92.      var so = $("#s2 option:selected");  
  93.       
  94.      if(so.get(so.length-1).index!=alloptions.length-1){  
  95.        for(i=so.length-1;i>=0;i--)  
  96.        {  
  97.          var item = $(so.get(i));  
  98.          item.insertAfter(item.next());  
  99.        }  
  100.      }  
  101.    });  
  102. });  
  103. -->  
  104. </script>  
  105. </head>  
  106.   
  107. <body>  
  108. <table width="288" border="0" cellpadding="0" cellspacing="0">  
  109.    <tr>  
  110.      <td width="29">  
  111.        <input type="button" name="s1up" id="s1up" value="↑" /><br />  
  112.      <input type="button" name="s1down" id="s1down" value="↓" /></td>  
  113.      <td width="100"><select name="s1" size="10" multiple="multiple" id="s1" style=" width:100px;">  
  114.        <option value="opt01">option01</option>  
  115.        <option value="opt02">option02</option>  
  116.        <option value="opt03">option03</option>  
  117.        <option value="opt04">option04</option>  
  118.        <option value="opt05">option05</option>  
  119.        <option value="opt06">option06</option>  
  120.        <option value="opt07">option07</option>  
  121.        <option value="opt08">option08</option>  
  122.        <option value="opt09">option09</option>  
  123.        <option value="opt10">option10</option>  
  124.      </select></td>  
  125.      <td width="37" align="center"><input type="button" name="addall" id="addall" value=">|" /><br /><input type="button" name="add" id="add" value=">>" /><br /><input type="button" name="remove" id="remove" value="<<" /><br /><input type="button" name="removeall" id="removeall" value="|<" /></td>  
  126.      <td width="100"><select name="s2" size="10" multiple="multiple" id="s2" style=" width:100px;">  
  127.      </select></td>  
  128.      <td width="119">  
  129.        <input type="button" name="s2up" id="s2up" value="↑" /><br />  
  130.      <input type="button" name="s2down" id="s2down" value="↓" /></td>  
  131.    </tr>  
  132. </table>  
  133. <p>支持直接双击添加/删除,上下(支持间隔)排序</p>  
  134. <p>jQuery Learning 群:24810664</p>  
  135. </body>  
  136. </html> 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值