Bootstrap3 实现穿梭框

使用 Bootstrap3 框架实现穿梭框代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!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>
坚持原创技术分享,您的支持将鼓励我继续创作!
0%