1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>Title</title>
6 </head>
7 <body>
8 <ul>
9 <li>111</li>
10 <li class="item">222</li>
11 <li>333</li>
12 </ul>
13 </body>
14 <script src="jquery-3.2.1.js"></script>
15 <script>
16 // 1、选择器+遍历
17 // $('div').each(function (i){
18 // i就是索引值
19 // this 表示获取遍历每一个dom对象
20 // });
21 // arr=[123,456,"hello"];
22 // $.each(arr,function (i) {
23 // console.log(i)
24 // })
25
26
27 // 2、选择器+遍历
28 // $('div').each(function (index,domEle){
29 // index就是索引值
30 // domEle 表示获取遍历每一个dom对象
31 // });
32 // arr=[123,456,"hello"];
33 // $.each(arr,function (i,j) {
34 // console.log(i);
35 // console.log(j);
36 // })
37
38 // obj={"name":'egon',"age":22};
39 // $.each(obj,function (i,j) {
40 // console.log(i);
41 // console.log(j);
42 // })
43
44 // 3、更适用的遍历方法
45 // 1)先获取某个集合对象
46 // 2)遍历集合对象的每一个元素
47 // var d=$("div");
48 // $.each(d,function (index,domEle){
49 // d是要遍历的集合
50 // index就是索引值
51 // domEle 表示获取遍历每一个dom对
52 // });
53 // $("ul li").each(function () {
54 // // console.log($(this));
55 // if ($(this).hasClass("item")){
56 // alert($(this).text())
57 //
58 // }
59 // })
60
61 </script>
62 </html>