1. 程式人生 > >jquery的each循環方式

jquery的each循環方式

pos scrip tle dex 每一個 set con item utf

 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>

jquery的each循環方式