$.each (Array, [callback]) traversal [common]
Explanation: Different from the $ (). each () method of the JQuery object, this method can be used to sample any object. 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. If you need to exit each loop so that the callback function returns false, the other return values are ignored.
Each traversal, I believe, is not strange, in the ordinary event processing, is a variant of the For loop, but more powerful than for loop. In the array, it can easily take the array index and the corresponding value. Cases:
The code is as follows |
Copy Code |
var _mozi=[' mohist ', ' Mozi ', ' Modi ', ' and love non-offensive ', ' still with Shangxian ']; The array used in this article, the same as $.each (_mozi,function (key,val) { The callback function has two parameters, the first is an element index, the second is the current value Alert (' _mozi array, index: ' +key+ ' corresponds to the value: ' +val '); }); |
For: relative to the native. In,each a little stronger. For: In can also iterate through the array and return the corresponding index, but the value needs to be obtained by Arrname[key]
var types = new Array ();
$ ("Input[name= ' Stypecheckbox ']:checked"). each (function (key,value) {
Types[key] = $ (this). Val ();
});
Key is index, value is