In jquery, the each traverses objects and array examples, jqueryeach
Generic Traversal method, which can be used to traverse objects and arrays. $ (). Each (), the callback function has two parameters:
The first is the index of the member or array of the object, and the second is the corresponding variable or content. To exit the each loop, the callback function returns false.
The following two select statements are available:
Plan category: <select id = "PLANTYPE"> <option value = "0">-all-</option> <option value = "1"> New </option> <option value = ""2"> renewal </option> </select> application type: <select id = "AUDITTYPE"> <option value = "0">-all-</option> <option value = "1"> declaration </option> <option value = "2"> modify </option> </select>
Use the each method to obtain the text value in option, that is,-all-, new, and continued creation...
If you only use an each loop once, you can start from option.
$ ("Option "). each (function (index, data) {console.info ($ (data ). text (); // or console.info ($ (this ). text ());})
It 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), indicating the option under this object
Otherwise, all options are used.
-------------------------- Gorgeous split line -----------------------------
Another method of each is jQuery. each (object, [callback]).
Unlike the $ (). each () method of the jQuery object, this method can be used to sample any object.
Use this method to traverse the above Code
$.each($("option"),function(index,data){ console.info(index+" "+data); })
You can also traverse the array.
$.each( [0,1,2], function(i, n){ console.info( "Index:" + i + ": " + n ); });
Traverse objects
$.each({ name: "itmyhome", addr: "Beijing" },function(i, n){ console.info("Name: " + i + ", Value: " + n); });
After jquery cyclically traverses the td in tabel by each, how can we integrate the specified td value into an array? First, very urgent
Hello, declare an Array var arr = new Array () outside the each ();
Then, append the value to the each using arr. push (6, 7. You must note that in each, you can use the this keyword to obtain the tag value from this loop.
Example: var arr = new Array ();
$ ("# T1 tbody tr input [name = 'sysnos [] ']: checked"). each (function (I, n ){
P_invNo = $ (n). parent (). parent (). children ("td: eq (1)"). text ();
P_cngNo = $ (n). parent (). parent (). children ("td: eq (2)"). text ();
P_endPrtName = $ (n). parent (). parent (). children ("td: eq (3)"). text ();
Arr. push (p_endPrtName); // append to here, and all values in arr are p_Piece =$ (n ). parent (). parent (). children ("td: eq (5 )"). text ();
P_payenders = $ (n). parent (). parent (). children ("td: eq (6)"). text ();
P_blenders = $ (n). parent (). parent (). children ("td: eq (8)"). text ();
Var p_lodUserName = $ ("# lodUserName"). val ();
});
Guo Libin [authoritative expert]
How does jquery traverse dom objects?
All DOM elements obtained using the $ () method in jQuery return an array and there is an invisible iteration in jQuery. You do not need to deliberately loop them in some operations, for example, $ ("div "). text ("hello"); then hello will be added to all the Divs. if you need to loop them for some processing, you can use the $. the each () method, or write as follows:
$ ("Div"). each (function (){
// Do what you want
// Use $ (this) to access elements in the loop
});
Happy learning!