-
Notifications
You must be signed in to change notification settings - Fork 0
/
jQuerySelectSimple.html
executable file
·70 lines (69 loc) · 2.76 KB
/
jQuerySelectSimple.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
<!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>
.top20 {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container top20">
<div class="row">
<div class="col-1">
</div>
<div class="col-8">
<form>
<div class="form-row align-items-center">
<div class="col-auto my-1">
<label class="mr-sm-2 sr-only" for="inlineFormCustomSelect">Preferencia</label>
<select class="custom-select mr-sm-2" id="inlineFormCustomSelect">
<option selected value="0">Elija...</option>
<option value="1">Haz el amor y no la guerra</option>
<option value="2">Cada día sabemos más y entendemos menos</option>
<option value="3">El mundo es bello, pero tiene un defecto llamado hombre</option>
</select>
</div>
</div>
</form>
<div>
<span id="selectContent"></span>
</div>
</div>
<div class="col-1">
</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>
const opciones = ['Nada elegido', 'Frase atribuida a John Lennon', 'Frase atribuida a Albert Einstein', 'Frase atribuida a Friedrich Nietzsche']
const origen = jQuery('#inlineFormCustomSelect')
const objetivo = jQuery('#selectContent')
origen.on('change', actualizar)
actualizar()
function actualizar() {
objetivo.empty().append(opciones[parseInt(jQuery('#inlineFormCustomSelect option:selected').val())])
}
</script>
</body>
</html>