-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQuerySelectMultiple.html
executable file
·80 lines (79 loc) · 2.75 KB
/
jQuerySelectMultiple.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description"
content="The faster, lighter and more secure version of the Bootstrap JavaScript components.">
<meta name="keywords" content="JavaScript,Native JavaScript,native,Bootstrap,plugins,jQuery">
<meta name="author" content="thednp">
<link rel="shortcut icon" href="../../bootstrap.native-master/assets/img/favicon.ico">
<link rel="apple-touch-icon" href="../../bootstrap.native-master/assets/img/apple-touch-icon.png">
<title>jQuery Template</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="../../bootstrap.native-master/assets/css/offcanvas.css">
<link rel="stylesheet" href="../../bootstrap.native-master/assets/css/prism.css">
<link rel="stylesheet" href="../../bootstrap.native-master/assets/css/theme.css">
<style>
.form-control {
height: 400px;
overflow: hidden;
}
#exampleFormControlSelect2 {
height: 400px;
overflow: hidden;
}
.top20 {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container top20">
<div class="row">
<div class="col-6">
<div class="form-group">
<label for="exampleFormControlSelect2">Seleccion multiple</label>
<select multiple class="form-control" id="exampleFormControlSelect2" onclick="mostrar()">
</select>
</div>
</div>
<div class="col-6">
Elegidos:
<ul id="elegidos">
</ul>
</div>
</div>
</div>
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap.native@3.0.5/dist/bootstrap-native.min.js"
integrity="sha256-CQiZw1XNLEFM6OEgZ8FR1/nTISQD7Y6i7m3beKI2BfM=" crossorigin="anonymous"></script>
<script src="lista.js"></script>
<script>
const listSelect = jQuery('#exampleFormControlSelect2')
const elegidos = jQuery('#elegidos')
listSelect.empty()
listaTotal.every(item => listSelect.append(templateOption(item)))
function mostrar() {
const listOptions = jQuery('#exampleFormControlSelect2 option:selected')
elegidos.empty()
listOptions.each(function (){
const item = listaTotal.find(element => element.index===parseInt(jQuery(this).val()))
if (!item) {
return
}
elegidos.append(templateLI(item))
})
}
function templateOption({titulo, index}) {
return `<option value="${index}">${titulo} (${index})</option>`
}
function templateLI({titulo: texto}) {
return `<li>${texto}</li>`
}
</script>
</body>
</html>