-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery11-Data.html
45 lines (41 loc) · 1.11 KB
/
jquery11-Data.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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Método Data</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).on('ready',function(){
//métodos útiles: each
// recorrer una colección:
// var col=['uno','dos','tres'];
// $.each(col, function(index,elem)
// { console.log(index+' '+ elem)
// });
// Localizar un elemento en una col $.inArray(valor,col)
// ese método devuelve el índice del elto o -1
//Elimina espacios al principio y al final de una cadena
//var cadena=' ho la ';
//$.trim(cadena)
//Método data sirve para escribir el par atributo-valor en
// el elemento indicado
// La estructura sería así: $.data(elemento, atributo,valor)
// ejemplo:
// $('ul li').each(function(index,elem){
//$.data(elem,'posicion',index);
//});
// Otro ejemplo de uso del método data
//$('ul li').each(function(index,elem) {
// console.log($.data(elem,'posicion'));
//})
});
</script>
</head>
<body>
<ul>
<li>uno</li>
<li>dos</li>
<li>tres</li>
</ul>
</body>
</html>