关键字:jQuery监听事件经典例子 





js代码: 

============================================================ 



$(function(){ 

   $("#s1 option:first,#s2 option:first").attr("selected",true); 

  

   $("#s1").dblclick(function(){ 

     var alloptions = $("#s1 option"); 

     var so = $("#s1 option:selected"); 



     so.get(so.length-1).index == alloptions.length-1?so.prev().attr("selected",true):so.next().attr("selected",true);

    

     $("#s2").append(so); 

   }); 

  

   $("#s2").dblclick(function(){ 

     var alloptions = $("#s2 option"); 

     var so = $("#s2 option:selected"); 

    

     so.get(so.length-1).index == alloptions.length-1?so.prev().attr("selected",true):so.next().attr("selected",true);

    

     $("#s1").append(so); 

   }); 

  

   $("#add").click(function(){ 

     var alloptions = $("#s1 option"); 

     var so = $("#s1 option:selected"); 



     so.get(so.length-1).index == alloptions.length-1?so.prev().attr("selected",true):so.next().attr("selected",true);

    

     $("#s2").append(so); 

   }); 

  

   $("#remove").click(function(){ 

     var alloptions = $("#s2 option"); 

     var so = $("#s2 option:selected"); 

    

     so.get(so.length-1).index == alloptions.length-1?so.prev().attr("selected",true):so.next().attr("selected",true);

    

     $("#s1").append(so); 

   }); 

  

   $("#addall").click(function(){ 

     $("#s2").append($("#s1 option").attr("selected",true)); 

   }); 

  

   $("#removeall").click(function(){ 

     $("#s1").append($("#s2 option").attr("selected",true)); 

   }); 

  

   $("#s1up").click(function(){ 

     var so = $("#s1 option:selected"); 

     if(so.get(0).index!=0){ 

       so.each(function(){ 

           $(this).prev().before($(this)); 

       }); 

     } 

   }); 

  

   $("#s1down").click(function(){ 

     var alloptions = $("#s1 option"); 

     var so = $("#s1 option:selected"); 

    

     if(so.get(so.length-1).index!=alloptions.length-1){ 

       for(i=so.length-1;i>=0;i--) 

       { 

         var item = $(so.get(i)); 

         item.insertAfter(item.next()); 

       } 

     } 

   }); 

  

   $("#s2up").click(function(){ 

     var so = $("#s2 option:selected"); 

     if(so.get(0).index!=0){ 

       so.each(function(){ 

           $(this).prev().before($(this)); 

       }); 

     } 

   }); 

  

   $("#s2down").click(function(){ 

     var alloptions = $("#s2 option"); 

     var so = $("#s2 option:selected"); 

    

     if(so.get(so.length-1).index!=alloptions.length-1){ 

       for(i=so.length-1;i>=0;i--) 

       { 

         var item = $(so.get(i)); 

         item.insertAfter(item.next()); 

       } 

     } 

   }); 

}); 

最新文章

  1. mybatis generator.xml 配置 自动生成model,dao,mapping
  2. (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
  3. easyui 》 radio取值,checkbox取值,select取值,radio选中,checkbox选中,select选中
  4. python中常用的函数与库一
  5. Can't bind to local 8700 for debugger报错和解决
  6. java 动态代理范例 InvocationHandler与Proxy
  7. 随意一条查询sql转换为查询结果集相应的数目
  8. tomcat中jsp编译
  9. NEC遥控信号解码(包含完整代码)
  10. jquery获取复选框
  11. C. Bits (Codeforces Round #276 (Div. 2) )
  12. 胡na娜、少年和恩师-写在甲午冬的仅仅言片语及感想
  13. iOS使用自定义字体的方法(内置和任意下载ttf\otf\ttc字体文件)
  14. .NET 自定义Json序列化时间格式
  15. Builder模式的思考(Effective Java)
  16. opencron
  17. Unity3D UGUI实现Toast
  18. Linux内核期末总结
  19. pdfcrop不能使用
  20. 用ADO操作数据库的方法步骤(ZT)

热门文章

  1. SSH深度历险(五) 深入浅出-----IOC AND AOP
  2. UNIX网络编程——客户/服务器程序设计示范(三)
  3. Android开发学习之路--MAC下Android Studio开发环境搭建
  4. 详解EBS接口开发之更新供应商付款方法
  5. JSP标签JSTL(4)--URL
  6. 使用HTML5拍照
  7. Uva - 1593 - Alignment of Code
  8. 【翻译】Ext JS最新技巧——2015-8-11
  9. PA 创建项目
  10. 【一天一道LeetCode】#78. Subsets