-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-exemplo-select.html
56 lines (49 loc) · 1.52 KB
/
1-exemplo-select.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
<!DOCTYPE html>
<html>
<head>
<title>Exemplos Javascript não obstrutivo</title>
<!-- ADICIONA CLASSE NO HTML QUANDO HA SUPORTE -->
<script>document.getElementsByTagName('html')[0].className += ' js'</script>
<style type="text/css">
.styleSelect {
width:200px;
background:white;
border:solid 1px #000;
}
.styleSelect span {
position:absolute;
}
.styleSelect select {
width:100%;
opacity:0;
filter:alpha(opacity=0);
}
</style>
</head>
<body>
<h1>Exemplo javascript não obstrutivo em select personalizado</h1>
<select title="Selecione">
<option value="1">Opção 1</option>
<option value="2">Opção 2</option>
<option value="3">Opção 3</option>
<option value="4">Opção 4</option>
<option value="5">Opção 5</option>
<option value="6">Opção 6</option>
</select>
<!-- TENTA CARREGAR JQUERY EXTERNO, EM CASO DE TIMEOUT CARREGA LOCAL -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="scripts/jquery-1.7.1.min.js"><\/script>')</script>
<script>
var select = $("select");
select.each(function() {
var self = $(this),
initialValue = self.attr("title") ? self.attr("title") : self.find("option:selected").text()
self.wrap('<div class="styleSelect"></div>')
self.css("position","relative").before('<span>'+ initialValue +'</span>')
});
select.bind("change keypress keydown keyup",function() {
$(this).prev().html($(this).find("option:selected").text())
});
</script>
</body>
</html>