Bootstrap3 实现穿梭框 发表于 2022-08-23 | 分类于 前端框架 , Bootstrap | | 浏览 次 字数统计: 731 | 阅读时长 ≈ 4 使用 Bootstrap3 框架实现穿梭框代码 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102<!doctype html><html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! --> <title>Bootstrap3 穿梭框</title> <!-- Bootstrap --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous"> <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询(media queries)功能 --> <!-- 警告:通过 file:// 协议(就是直接将 html 页面拖拽到浏览器中)访问页面时 Respond.js 不起作用 --> <!--[if lt IE 9]> <script src="https://cdn.jsdelivr.cn/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script> <script src="https://cdn.jsdelivr.cn/npm/respond.js@1.4.2/dest/respond.min.js"></script> <![endif]--> </head> <body> <h1 class="text-center">Bootstrap3 穿梭框</h1> <fieldset> <table class="table table-bordered dchannel-table"> <tbody> <tr class="item-default"> <td style="width: 50%;"> <select id="sel_all_area" multiple="multiple" size="10" style="width:100%;"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> </td> <td style="width: 50px;"> <button type="button" class="btn btn-default btn-small" id="btn_select_all_area"><span class="glyphicon glyphicon-forward"></span></button> <button type="button" class="btn btn-default btn-small" id="btn_choose_selected_area"><span class="glyphicon glyphicon-chevron-right"></span></button> <button type="button" class="btn btn-default btn-small" id="btn_remove_selected_area"><span class="glyphicon glyphicon-chevron-left"></span></button> <button type="button" class="btn btn-default btn-small" id="btn_remove_all_area"><span class="glyphicon glyphicon-backward"></span></button> </td> <td style="width: 50%;"> <select id="sel_selected_areas" multiple="multiple" size="10" style="width:100%;"> </select> </td> </tr> </tbody> </table> </fieldset> <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) --> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js" crossorigin="anonymous"></script> <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 --> <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script> <script> $(function(){ var all_area = $("#sel_all_area"), selected_areas = $("#sel_selected_areas"); $("#btn_select_all_area").click(function(){ var selectedAreaArray = []; all_area.find("option").each(function(i){ selectedAreaArray[i] = $(this).val(); $(this).appendTo(selected_areas); }); doSubmit('add', selectedAreaArray.toString()); return false; }); $("#btn_choose_selected_area").click(function(){ var selectedAreaArray = []; all_area.find("option:selected").each(function(i){ selectedAreaArray[i] = $(this).val(); $(this).appendTo(selected_areas); }); doSubmit('add', selectedAreaArray.toString()); return false; }); $("#btn_remove_selected_area").click(function(){ var selectedAreaArray = []; selected_areas.find("option:selected").each(function(i){ selectedAreaArray[i] = $(this).val(); $(this).appendTo(all_area); }); doSubmit('del', selectedAreaArray.toString()); return false; }); $("#btn_remove_all_area").click(function(){ var selectedAreaArray = []; selected_areas.find("option").each(function(i){ selectedAreaArray[i] = $(this).val(); $(this).appendTo(all_area); }); doSubmit('del', selectedAreaArray.toString()); return false; }); }) function doSubmit(select_type, key){ console.log(`更新 类型: ${select_type}, KEY: ${key}`); } </script> </body></html> 坚持原创技术分享,您的支持将鼓励我继续创作! 打赏 微信支付 支付宝 本文作者: Peak Xin 本文链接: https://xinyufeng.net/2022/08/23/Bootstrap3-实现穿梭框/ 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!