zoukankan      html  css  js  c++  java
  • JQuery MultiSelect(左右选择框)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <title>demo</title>
        <script src="jquery-1.4.4.min.js"></script>
        <script>
        $(function(){
            //选择一项
            $("#addOne").click(function(){
                $("#from option:selected").clone().appendTo("#to");
                $("#from option:selected").remove();
            });
     
            //选择全部
            $("#addAll").click(function(){
                $("#from option").clone().appendTo("#to");
                $("#from option").remove();
            });
     
            //移除一项
            $("#removeOne").click(function(){
                $("#to option:selected").clone().appendTo("#from");
                $("#to option:selected").remove();
            });
     
            //移除全部
            $("#removeAll").click(function(){
                $("#to option").clone().appendTo("#from");
                $("#to option").remove();
            });
     
            //移至顶部
            $("#Top").click(function(){
                var allOpts = $("#to option");
                var selected = $("#to option:selected");
     
                if(selected.get(0).index!=0){
                    for(i=0;i<selected.length;i++){
                       var item = $(selected.get(i));
                       var top = $(allOpts.get(0));
                       item.insertBefore(top);
                    }
                }
            });
     
            //上移一行
            $("#Up").click(function(){
                var selected = $("#to option:selected");
                if(selected.get(0).index!=0){
                    selected.each(function(){
                        $(this).prev().before($(this));
                    });
                }
            });
     
            //下移一行
            $("#Down").click(function(){
                var allOpts = $("#to option");
                var selected = $("#to option:selected");
     
                if(selected.get(selected.length-1).index!=allOpts.length-1){
                    for(i=selected.length-1;i>=0;i--){
                       var item = $(selected.get(i));
                       item.insertAfter(item.next());
                    }
                }
            });
     
            //移至底部
            $("#Buttom").click(function(){
                var allOpts = $("#to option");
                var selected = $("#to option:selected");
     
                if(selected.get(selected.length-1).index!=allOpts.length-1){
                    for(i=selected.length-1;i>=0;i--){
                       var item = $(selected.get(i));
                       var buttom = $(allOpts.get(length-1));
                       item.insertAfter(buttom);
                    }
                }
            });
        });
        </script>
      </head>
    <body>
    <table align="center" width="288" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="4">
                <select name="from" id="from" multiple="multiple" size="10" style="100%">
                    <option value="1">选项1</option>
                    <option value="2">选项2</option>
                    <option value="3">选项3</option>
                    <option value="4">选项4</option>
                    <option value="5">选项5</option>
                    <option value="6">选项6</option>
                    <option value="7">选项7</option>
                </select>
            </td>
            <td align="center">
                <input type="button" id="addAll" value=" >> " style="50px;" /><br />
                <input type="button" id="addOne" value=" > " style="50px;" /><br />
                <input type="button" id="removeOne" value="&lt;" style="50px;" /><br />
                <input type="button" id="removeAll" value="&lt;&lt;" style="50px;" /><br />
            </td>
            <td colspan="4">
                <select name="to" id="to" multiple="multiple" size="10" style="100%">
                </select>
            </td>
            <td align="center">
                <input type="button" id="Top" value="置顶" style="50px;" /><br />
                <input type="button" id="Up" value="上移" style="50px;" /><br />
                <input type="button" id="Down" value="下移" style="50px;" /><br />
                <input type="button" id="Buttom" value="置底" style="50px;" /><br />
            </td>
        </tr>
    </table>
    </body>
    </html>
  • 相关阅读:
    Sogou C++ Workflow 安装与使用例子
    Ubuntu c++ 使用mysql++ 链接mysql 使用cmake 构建
    现代cmake 从github引入三方库,使用FetchContent ( 3.14 以上版本)
    Vue3 + TypeScript 开发实践总结
    Spring MVC 学习总结(十)——Spring+Spring MVC+MyBatis框架集成(IntelliJ IDEA SSM集成)
    Spring MVC 学习总结(九)——Spring MVC实现RESTful与JSON(Spring MVC为前端提供服务)
    Spring MVC 学习总结(八)——Spring MVC概要与环境配置(IDEA+Maven+Tomcat7+JDK8、示例与视频)
    Spring MVC 学习总结(六)——Spring+Spring MVC+MyBatis框架集成
    Spring MVC 学习总结(五)——校验与文件上传
    Spring MVC 学习总结(四)——视图与综合示例
  • 原文地址:https://www.cnblogs.com/iteakey/p/4171640.html
Copyright © 2011-2022 走看看