Each of the jquery can be used to iterate over objects and arrays, so that the callback function returns False if you want to exit each loop
1.$ (). each (), the callback function has two parameters:
The first is the index of the object's member or array, and the second is the corresponding variable or content. Return the callback function to False if you want to exit each loop
Example:
There are currently two select
Program Category: <select id= "Plantype" > <option value= "0" >-all-</option> <option value= "1" > New </option > <option value= "2" > Continuation </option> </select> declaration type: <select id= "Audittype" > <option value= "0 ">-all-</option> <option value=" 1 "> Declaration </option> <option value=" 2 "> Modify </option> </ Select>
Goal: Use the each method to get the text value in option-all-, new, build, all.
$ ("option"). each (function (index,data) {Console.info ($ (data). text ());//or Console.info ($ (this). text ());})
You can also start at select
$ ("select"). each (function (index,data) {$ ("option", data). Each (function (m,n) {Console.info ($ (this). Text ())})
$ ("option", data) must be added with data or $ ("option", this) to indicate option under this object, otherwise it is all option.
--------------------------Gorgeous split-line-----------------------------
2. Jquery.each (object, [callback]), unlike the $ (). each () method of a JQuery object, this method can be used to sample any object.
Use this method to also traverse the above code:
$.each ($ ("option"), function (Index,data) {Console.info (index+ "" +data);})
To iterate over an array:
$.each ([0,1,2], function (i, n) {console.info ("Index:" + i + ":" + N);});
To traverse an object:
$.each ({name: "Itmyhome", Addr: "Beijing"},function (i, N) {console.info ("name:" + i + ", Value:" + N);});
Each traversal object and array in jquery