A universal traversal method that can be used to traverse objects and arrays. $ (). 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
There are currently two select
?
| 123456789101112 |
计划类别: <select id="PLANTYPE"> <option value="0">-所有-</option> <option value="1">新建</option> <option value="2">续建</option> </select> 申报类型: <select id="AUDITTYPE"> <option value="0">-所有-</option> <option value="1">申报</option> <option value="2">修改</option> </select> |
Use the each method to get the text value in option, that is-all-, new, continued ...
If you use only once each loop, you can start at option
?
| 1234 |
$("option").each(function(index,data){ console.info($( data ).text()); //或者console.info($(this).text()); }) |
You can also start at select
?
| 12345 |
$("select").each(function( index,data){ $("option", data).each(function(m,n){ console.info($(this).text()); }) }) |
$ ("option", data) Be sure to add data or $ ("option", this), which represents the option under this object
Otherwise, it's all option.
--------------------------Gorgeous split-line-----------------------------
Each also has a usage 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 traverse the same code
?
| 123 |
$.each($("option"),function(index,data){ console.info(index+" "+data); }) |
You can also iterate over an array
?
| 123 |
$.each( [0,1,2], function(i, n){ console.info( "Index:"+ i + ": "+ n ); }); |
Traversing objects
?
| 123 |
$.each({ name: "itmyhome", addr: "Beijing"},function(i, n){ console.info("Name: " + i + ", Value: "+ n); });
|
Each traversal object and array example in jquery