Some time ago, the project needed to use two-way list selection. I wanted to use select directly. It turned out that some styles were not supported, so I had to use div to simulate the following. The function was basically implemented and available. You need to add other functions by yourself, such as displaying multiple items in the list. Column data, etc.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>雙向列表選擇器DIV模擬</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"); //是否按下了shift var is_shift=false; //是否按下了ctrl var is_ctrl=false; document.addEventListener("keydown",function(e){ is_shift=e.shiftKey; is_ctrl=e.ctrlKey; },false); document.addEventListener("keyup",function(e){ is_shift = is_ctrl = false; },false); //進行排序 var option_sort=function(o){ o.html(o.find("div").toArray().sort(function(a, b){ return parseInt($(a).attr("data-index")) - parseInt($(b).attr("data-index")); })); obj.find(".item").removeClass("is_select"); obj.find(".item").unbind("dblclick").dblclick(function(){ _dblclick($(this)); }); obj.find(".item").unbind("click").click(function(){ _click($(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); } } //在列表中單擊時 var temp_index=0; var _click=function(o){ var flag=o.parent().attr("class"); if(is_shift){ var this_index=o.index(); if(temp_index!=this_index){ obj.find("."+flag+" .item").each(function(index, element) { if(this_index>temp_index && index<this_index && index>=temp_index){ $(this).addClass("is_select"); } if(this_index<temp_index && index>this_index && index<=temp_index){ $(this).addClass("is_select"); } }); } } if(!is_ctrl && !is_shift){ obj.find("."+flag+" .item").each(function() { $(this).removeClass("is_select"); }); } if(o.hasClass("is_select")){ o.removeClass("is_select"); }else{ o.addClass("is_select"); } temp_index=o.index(); } //選項單擊時 obj.find(".item").click(function(){ _click($(this)); }); //選項雙擊時 obj.find(".item").dblclick(function(){ _dblclick($(this)); }); //加入選中 btn_a.click(function(){ var a = select_a.find(".is_select").clone(true); if(a.size() == 0){ return false; } select_b.append(a); select_a.find(".is_select").remove(); option_sort(select_b); }); //刪除選中 btn_b.click(function(){ var a = select_b.find(".is_select").clone(true); if(a.size() == 0){ return false; } select_a.append(a); select_b.find(".is_select").remove(); option_sort(select_a); }); //刪除全部 btn_c.click(function(){ select_a.append(select_b.find("div")); option_sort(select_a); }); //加入全部 btn_d.click(function(){ select_b.append(select_a.find("div")); 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; } .two_way_list_selector .select_l .option .l { width: 30%; float: left; text-indent: 10px; } .two_way_list_selector .select_l .option .r { width: 70%; float: right; text-align: center; } .two_way_list_selector .select_l .select_a, .two_way_list_selector .select_r .select_b { width: 100%; height: 220px; overflow: auto; } .two_way_list_selector .select_r .select_b { height: 250px; } .two_way_list_selector .select_l .select_a div, .two_way_list_selector .select_r .select_b div { padding: 10px; height: 25px; line-height: 25px; border-bottom: 1px solid #ddd; background: #FFF; } .two_way_list_selector .select_l .select_a div:last-child, .two_way_list_selector .select_r .select_b div: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; } .two_way_list_selector .select_l .select_a .is_select, .two_way_list_selector .select_r .select_b .is_select { color: #FFF; background: #3399FF; } </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 class="l">名稱</div> <div class="r"><a>數(shù)量</a></div> </div> <div class="select_a"> <div data-value="1" data-index="0" class="item">1</div> <div data-value="2" data-index="1" class="item">2</div> <div data-value="3" data-index="2" class="item">3</div> <div data-value="4" data-index="3" class="item">4</div> <div data-value="5" data-index="4" class="item">5</div> <div data-value="6" data-index="5" class="item">6</div> <div data-value="7" data-index="6" class="item">7</div> </div> </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"> <div class="select_b"></div> </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 class="l">名稱</div> <div class="r"><a>數(shù)量</a></div> </div> <div class="select_a"> <div data-value="a" data-index="0" class="item">a</div> <div data-value="b" data-index="1" class="item">b</div> <div data-value="c" data-index="2" class="item">c</div> <div data-value="d" data-index="3" class="item">d</div> <div data-value="e" data-index="4" class="item">e</div> <div data-value="f" data-index="5" class="item">f</div> <div data-value="g" data-index="6" class="item">g</div> </div> </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"> <div class="select_b"></div> </div> </div> </body> </html>
The above is the jQuery two-way list selector DIV simulation version introduced by the editor. I hope it will be helpful to everyone

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

jQuery is a fast, small, feature-rich JavaScript library widely used in front-end development. Since its release in 2006, jQuery has become one of the tools of choice for many developers, but in practical applications, it also has some advantages and disadvantages. This article will deeply analyze the advantages and disadvantages of jQuery and illustrate it with specific code examples. Advantages: 1. Concise syntax jQuery's syntax design is concise and clear, which can greatly improve the readability and writing efficiency of the code. for example,

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on ??the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:
