热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

jquery双向列表选择器select版

这个是select版的,若想美化某些样式是不支持得,可以用div模拟版的,功能基本实现能用了,需要其他功能自己加上。div模拟版链接:http:www.cnblogs.comtie123abcp6018755.html<!doctypehtml><html>&am

jquery双向列表选择器select版这个是select版的,若想美化某些样式是不支持得,可以用div模拟版的,功能基本实现能用了,需要其他功能自己加上。

div模拟版链接:http://www.cnblogs.com/tie123abc/p/6018755.html

doctype html>
<html>
<head>
<meta charset="utf-8">
<title>双向列表选择器select版title>
<script type="text/Javascript" src="../public/jquery-1.8.2.js">script>
<script type="text/Javascript">

/**
 * two_way_list_selector.js - v1.0.0 (2016/7/26)
 *
 * Allows you to easily page layout!
 * by tie. qq:2185987263
 *
 * Copyright (C) 2016, tie.
 * All rights reserved.
 *
 **/

var two_way_list_selector=function(o){

    var obj=o;
    var btn_a=o.find(".btn_a");
    var btn_b=o.find(".btn_b");
    var btn_c=o.find(".btn_remove_all");
    var btn_d=o.find(".btn_add_all");
    var select_a=o.find(".select_a");
    var select_b=o.find(".select_b");
    
    //进行排序
    var option_sort=function(o){
        o.html(o.find("option").toArray().sort(function(a, b){
            return parseInt($(a).attr("data-index")) - parseInt($(b).attr("data-index"));
        }));
        obj.find("option").unbind("dblclick").dblclick(function(){
            _dblclick($(this));
        });
    }

    //在列表中双击时
    var _dblclick=function(o){
        var flag = o.parent().attr('class');
        var a ;
        if(flag == "select_a"){
            a = o.clone(true);
            select_b.append(a);
            o.remove();
            option_sort(select_b);
        } else {
            a = o.clone(true);
            select_a.append(a);
            o.remove();
            option_sort(select_a);
        }
    }

    //选项双击时
    obj.find("option").dblclick(function(){
        _dblclick($(this));
    });

    //加入选中
    btn_a.click(function(){
        var a = select_a.find("option:selected").clone(true);
        if(a.size() == 0){
            return false;
        }
        select_b.append(a);
        select_a.find("option:selected").remove();
        option_sort(select_b);
    });

    //删除选中
    btn_b.click(function(){
        var a = select_b.find("option:selected").clone(true);
        if(a.size() == 0){
            return false;
        }
        select_a.append(a);
        select_b.find("option:selected").remove();
        option_sort(select_a);
    });

    //删除全部
    btn_c.click(function(){
        select_a.append(select_b.find("option"));
        option_sort(select_a);
    });

    //添加全部
    btn_d.click(function(){
        select_b.append(select_a.find("option"));
        option_sort(select_b);
    });
}

//页面加载完毕后
$(document).ready(function(e) {
    two_way_list_selector($("#two_way_list_selector_a"));
    two_way_list_selector($("#two_way_list_selector_b"));
});

script>
<style type="text/css">
@charset "utf-8";
.two_way_list_selector {
    width: 100%;
    height: 250px;
}
.two_way_list_selector .select_l, .two_way_list_selector .select_r {
    width: 40%;
    height: 250px;
    float: left;
    border: 1px solid #CCC;
}
.two_way_list_selector .select_l .option {
    height: 29px;
    line-height: 29px;
    border-bottom: 1px solid #ddd;
    text-indent:10px;
}
.two_way_list_selector .select_l select, .two_way_list_selector .select_r select {
    width: 100%;
    height: 220px;
    border: none;
    outline: none;
}
.two_way_list_selector .select_r select {
    height: 250px;
}
.two_way_list_selector .select_l select:hover, .two_way_list_selector .select_r select:hover {
    border: none;
    box-shadow: none;
}
.two_way_list_selector .select_l select option, .two_way_list_selector .select_r select option {
    padding: 10px;
    border-bottom: 1px solid #ddd;
}
.two_way_list_selector .select_l select option:last-child, .two_way_list_selector .select_r select option:last-child {
    border-bottom: none;
}
.two_way_list_selector .select_btn {
    width: 10%;
    height: 250px;
    float: left;
    display: table;
    text-align: center;
}
.two_way_list_selector .select_btn div {
    height: 250px;
    display: table-cell;
    vertical-align: middle;
}
.two_way_list_selector .select_btn div input {
    width: 90%;
    margin: 1px;
    text-align: center;
    font-weight: 100;
    color: #999;
}
style>
head>

<body>
<div id="two_way_list_selector_a" class="two_way_list_selector margin_top_10">
  <div class="select_l">
    <div class="option">名称div>
    <select size="5" multiple class="select_a">
      <option value="1" data-index="0">1option>
      <option value="2" data-index="1">2option>
      <option value="3" data-index="2">3option>
      <option value="4" data-index="3">4option>
      <option value="5" data-index="4">5option>
      <option value="6" data-index="5">6option>
      <option value="7" data-index="6">7option>
    select>
  div>
  <div class="select_btn">
    <div>
      <input type="button" value=">" class="button btn_a">
      <input type="button" value=">>" class="button btn_add_all">
      <input type="button" value="<<" class="button btn_remove_all">
      <input type="button" value="<" class="button btn_b">
    div>
  div>
  <div class="select_r">
    <select size="5" multiple class="select_b">
    select>
  div>
div>

<br>

<div id="two_way_list_selector_b" class="two_way_list_selector margin_top_10">
  <div class="select_l">
    <div class="option">名称div>
    <select size="5" multiple class="select_a">
      <option value="a" data-index="0">aoption>
      <option value="b" data-index="1">boption>
      <option value="c" data-index="2">coption>
      <option value="d" data-index="3">doption>
      <option value="e" data-index="4">eoption>
      <option value="f" data-index="5">foption>
      <option value="g" data-index="6">goption>
    select>
  div>
  <div class="select_btn">
    <div>
      <input type="button" value=">" class="button btn_a">
      <input type="button" value=">>" class="button btn_add_all">
      <input type="button" value="<<" class="button btn_remove_all">
      <input type="button" value="<" class="button btn_b">
    div>
  div>
  <div class="select_r">
    <select size="5" multiple class="select_b">
    select>
  div>
div>
body>
html>

 


推荐阅读
author-avatar
王俞宇淑珮_166
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有