In jquery, each can be used to traverse objects and arrays. to exit the each loop, the callback function returns false. The following example shows a general Traversal method, it 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: -All- New Continued construction Application Type: -All- Declaration Modify
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); });