1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Title</title>6 </Head>7 <Body>8 <ul>9 <Li>111</Li>Ten <Liclass= "Item">222</Li> One <Li>333</Li> A </ul> - </Body> - <Scriptsrc= "Jquery-3.2.1.js"></Script> the <Script> - //1. Selector + traversal - //$ (' div '). each (function (i) { - //i is the index value + //This means get traversal of each DOM object - // }); + //arr=[123,456, "Hello"]; A //$.each (arr,function (i) { at //Console.log (i) - // }) - - - //2. Selector + traversal - //$ (' div '). each (function (Index,domele) { in //index is the indexed value - //Domele means get traversal of each DOM object to // }); + //arr=[123,456, "Hello"]; - //$.each (arr,function (i,j) { the //Console.log (i); * //Console.log (j); $ // })Panax Notoginseng - //obj={"name": ' Egon ', ' Age ':-}; the //$.each (obj,function (i,j) { + //Console.log (i); A //Console.log (j); the // }) + - //3. More suitable traversal method $ //1) Get a collection object first $ //2) iterate through each element of a collection object - //var d=$ ("div"); - //$.each (d,function (index,domele) { the //D is the collection to traverse - //index is the indexed valueWuyi //the Domele represents a fetch that iterates through each DOM pair the // }); - //$ ("ul Li"). each (function () { Wu ////Console.log ($ (this)); - //if ($ (this). Hasclass ("item")) { About //Alert ($ (this). Text ()) $ // - // } - // }) - A </Script> + </HTML>
Each loop way of jquery