forked from Janking/dropdown
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
228 lines (210 loc) · 6.08 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Dropdown.js - a lightweight dropdown of jQuery plugins </title>
<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script type="text/javascript" src="./mock.js"></script>
<script src="https://cdn.bootcss.com/jquery/1.8.1/jquery.js"></script>
<link rel="stylesheet" type="text/css" href="./jquery.dropdown.min.css">
<script src="./jquery.dropdown.js"></script>
<style>
body {
width: 80%;
margin: 0 auto;
padding-bottom: 200px;
}
</style>
</head>
<body>
<form action="">
<h2>程序逻辑</h2>
<img src="http://images.vrm.cn/2017/03/21/WX20170321-174303.png">
<h2> Demo</h2>
<br>
<div class="row">
<div class="col-sm-4">
<div class="text-info">多选、JSON渲染、分组功能</div>
<br>
<div class="dropdown-mul-1">
<select style="display:none" name="" id="" multiple placeholder="请选择"> </select>
</div>
</div>
<div class="col-sm-4" style="margin-top:40px;">
<button class="btn btn-primary btn-sm" id="update">AJAX更新数据</button>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4">
<div class="text-info">多选、Option渲染</div>
<br>
<div class="dropdown-mul-2">
<select style="display:none" name="" id="mul-2" multiple placeholder="请选择">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3" selected>我是默认选中的</option>
<option value="4" disabled>4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4">
<div class="text-info">单选模式,Option渲染</div>
<br>
<div class="dropdown-sin-1">
<select style="display:none" placeholder="请选择:测试placeholder">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">我是默认选中的</option>
<option value="4" disabled>4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-sm-4">
<div class="text-info">100 条数据搜索测试</div>
<br>
<div class="dropdown-sin-2">
<select style="display:none" multiple placeholder="请选择:测试placeholder"></select>
</div>
</div>
<div class="col-sm-4" style="margin-top:40px;">
<button class="btn btn-primary btn-sm" id="update2">AJAX更新数据</button>
<button class="btn btn-primary btn-sm" id="reset">reset</button>
</div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</form>
<script>
var Random = Mock.Random;
var json1 = Mock.mock({
"data|10-50": [{
name: function () {
return Random.name(true)
},
"id": function () {
return Random.cword(3);
},
"one": function () {
return Random.name(true)
},
"two": function () {
return Random.name(true)
},
"disabled|1-2": true,
groupName: '分组名',
"groupId|1-4": 1,
"selected": false
}]
});
$('.dropdown-mul-1').dropdown({
data: json1.data,
limitCount: 40,
multipleMode: 'label',
choice: function () {
console.log(arguments, this);
}
});
var json2 = Mock.mock({
"data|100-200": [{
name: function () {
return Random.name(true)
},
"id|+1": 1,
"disabled": false,
groupName: '分组名',
"groupId|1-4": 1,
"selected": false
}]
});
Mock.mock('/update', {
"data|51-100": [{
name: function () {
return Random.name(true)
},
"id|+1": 101,
"disabled|1-2": true,
groupName: '分组名',
"groupId|1-4": 1,
"selected": false
}]
});
Mock.mock('/update2', {
"data|201-300": [{
name: function () {
return Random.name(true)
},
"id|+1": 201,
"disabled": false,
groupName: '分组名',
"groupId|1-4": 1,
"selected": false
}]
});
$('.dropdown-mul-2').dropdown({
minCount: 2,
minCountErrorMessage: 'You need to select at least 2 options!',
limitCount: 4,
limitCountErrorMessage: 'You cannot select more than 4 options!',
searchable: false,
choice: function () {
console.log('.dropdown-mul-2 picked')
}
});
$('#update').on('click', function (event) {
event.preventDefault();
$.get('/update', function (res) {
$('.dropdown-mul-1').data('dropdown').update(JSON.parse(res).data, true);
});
});
$('.dropdown-sin-1').dropdown({
readOnly: true,
input: '<input type="text" maxLength="20" placeholder="请输入搜索">',
choice: function () {
console.log(arguments, this);
}
});
$('.dropdown-sin-2').dropdown({
data: json2.data,
input: '<input type="text" maxLength="20" placeholder="请输入搜索">',
choice: function () {
console.log(arguments, this);
}
});
$('#update2').on('click', function (event) {
event.preventDefault();
$.get('/update', function (res) {
$('.dropdown-sin-2').data('dropdown').update(JSON.parse(res).data, false);
});
});
var test = $('.dropdown-sin-1').data('dropdown')
$('#reset').on('click', function () {
event.preventDefault();
$('.dropdown-sin-2').data('dropdown').reset()
})
</script>
</body>
</html>