-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
182 lines (165 loc) · 6.05 KB
/
index.html
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link href="//unpkg.com/layui@2.9.7/dist/css/layui.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="layui-container" style="width: 500px">
<form class="layui-form">
<div class="layui-form-item">
<label class="layui-form-label">城市</label>
<div class="layui-input-block">
<input id="multi-select1" name="cities1" class="layui-input" readonly lay-verify="required" placeholder="请选择" />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">城市</label>
<div class="layui-input-block">
<div class="layui-input-group" style="width 100%;">
<div class="layui-input-split layui-input-prefix">
前缀前缀
</div>
<input id="multi-select2" name="cities2" class="layui-input" readonly lay-verify="required" placeholder="请选择" />
<div class="layui-input-split layui-input-suffix">
后缀
</div>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">城市</label>
<div class="layui-input-block">
<input id="multi-select3" name="cities3" class="layui-input" readonly lay-verify="required" placeholder="请选择" />
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">城市</label>
<div class="layui-input-block">
<input id="multi-select4" name="cities4" class="layui-input" readonly lay-verify="required" placeholder="请选择" />
</div>
</div>
<button class="layui-btn" lay-submit lay-filter="demo-verify">提交</button>
<button class="layui-btn" type="button" id="reload">重载</button>
</form>
<input id="multi-select5" name="cities5" class="layui-input" readonly lay-verify="required" placeholder="请选择" />
<h3>URL</h3>
<input id="multi-select6" name="cities6" class="layui-input" readonly lay-verify="required" placeholder="请选择" />
</div>
<script src="//unpkg.com/layui@2.9.7/dist/layui.js"></script>
<script>
layui.config({
base: '/layui-multiple-select/'
}).extend({
select: 'select'
});
layui.use(['select', 'form'], function() {
const select = layui.select;
const form = layui.form;
const $ = layui.$;
var selected = true;
for(let i = 1; i <= 3; i++) {
select.render({
elem: '#multi-select' + i,
keywordPlaceholder: '关键词',
unfilteredText: '没有匹配的选项',
collapseSelected: true,
options: [
{id: 1,title: '北京', selected: selected},
{id: 2,title: '上海', selected: selected},
{id: 3,title: '湖北', selected: selected},
{id: 4,title: '湖南', selected: selected},
{id: 5,title: '河北', selected: selected},
{id: 6,title: '山西', selected: selected},
{id: 7,title: '内蒙古', selected: selected},
{id: 8,title: '西藏', selected: selected},
{id: 9,title: '台湾', selected: selected},
{id: 10,title: '新疆', selected: selected},
{id: 11,title: '天津', selected: selected},
{id: 12,title: '山东', selected: selected},
{id: 13,title: '浙江'},
{id: 14,title: '福建'},
{id: 15,title: '广西'},
{id: 16,title: '贵州'},
{id: 17,title: '四川'},
],
});
}
select.render({
elem: '#multi-select4',
keywordPlaceholder: '关键词',
unfilteredText: '没有匹配的选项',
options: [
{id: 1,title: '北京', selected: false},
{id: 2,title: '上海', selected: selected},
{id: 3,title: '湖北', selected: false},
{id: 4,title: '湖南', selected: selected},
{id: 5,title: '河北', selected: false},
{id: 6,title: '山西', selected: selected},
{id: 7,title: '内蒙古', selected: false},
{id: 8,title: '西藏', selected: selected},
{id: 9,title: '台湾', selected: false},
{id: 10,title: '新疆', selected: false},
{id: 11,title: '天津', selected: false},
{id: 12,title: '山东', selected: false},
{id: 13,title: '浙江'},
{id: 14,title: '福建'},
{id: 15,title: '广西'},
{id: 16,title: '贵州'},
{id: 17,title: '四川'},
],
});
const select5 = select.render({
elem: '#multi-select5',
keywordPlaceholder: '关键词',
unfilteredText: '没有匹配的选项',
options: [
{id: 1,title: '北京', selected: false},
{id: 2,title: '上海', selected: selected},
{id: 3,title: '湖北', selected: false},
{id: 4,title: '湖南', selected: selected},
{id: 5,title: '河北', selected: false},
{id: 6,title: '山西', selected: selected},
{id: 7,title: '内蒙古', selected: false},
{id: 8,title: '西藏', selected: selected},
{id: 9,title: '台湾', selected: false},
{id: 10,title: '新疆', selected: false},
{id: 11,title: '天津', selected: false},
{id: 12,title: '山东', selected: false},
{id: 13,title: '浙江'},
{id: 14,title: '福建'},
{id: 15,title: '广西'},
{id: 16,title: '贵州'},
{id: 17,title: '四川'},
],
});
const select6 = select.render({
elem: '#multi-select6',
keywordPlaceholder: '关键词',
unfilteredText: '没有匹配的选项',
url: 'options.json'
});
$('#reload').click(function() {
select5.reload({
options: [{id: 1,title: '北京'}, {id: 2,title: '上海'}, {id: 3,title: '湖北'}, {id: 4,title: '湖南'}],
});
select5.val('1,4')
});
// 提交事件
form.on('submit(demo-verify)', function(data){
var field = data.field; // 获取表单字段值
// 显示填写结果,仅作演示用
layer.alert(JSON.stringify(field), {
title: '当前填写的字段值'
});
// 此处可执行 Ajax 等操作
// …
return false; // 阻止默认 form 跳转
});
});
</script>
</body>
</html>