jQuery.each()与.each()理解与用法
2010-12-07 11:47
435 查看
刚在学习写些jQuery的插件,当写得循环语句时自己有点蒙了,搞不清如何区分和使用jQuery.each()与.each()了。为了仔细了解他
们之间的异同,我很认真的查看了官方的文档(http://api.jquery.com/jQuery.each/)
$.each()函数与.each()的不同在于:
.each()是通过一个jQuery对象来调用,遍历并执行对象内的每一个元素,示例:$(".box").each(function(){}),其遍历jQuery对象
集合里的每一个元素。
而$.each()刚可以用与遍历任何的集合,map,array之类的,当然对象也没问题。调用时只要将要遍历的对象作为第一个参数放进去
便行。示例:$.each([52, 97], function(index, value) {
alert(index + ': ' + value);
});
像Array的话,回调函数内参数提供一个索引与其相应值。
官方文档原文:The $.each() function is not the same as .each(), which is used to iterate, exclusively, over a jQuery
object. The $.each() function can be used to iterate over any collection, whether it is a map (JavaScript object) or
an array. In the case of an array, the callback is passed an array index and a corresponding array value each time.
(The value can also be accessed through the this keyword, but Javascript will always wrap the this value as an
Object even if it is a simple string or number value.) The method returns its first argument, the object that was
iterated.
如有哪里写得不对,请大家指教~
个人有关JQuery插件的网站,请支持:jqueryhtml5.webege.com
们之间的异同,我很认真的查看了官方的文档(http://api.jquery.com/jQuery.each/)
$.each()函数与.each()的不同在于:
.each()是通过一个jQuery对象来调用,遍历并执行对象内的每一个元素,示例:$(".box").each(function(){}),其遍历jQuery对象
集合里的每一个元素。
而$.each()刚可以用与遍历任何的集合,map,array之类的,当然对象也没问题。调用时只要将要遍历的对象作为第一个参数放进去
便行。示例:$.each([52, 97], function(index, value) {
alert(index + ': ' + value);
});
像Array的话,回调函数内参数提供一个索引与其相应值。
官方文档原文:The $.each() function is not the same as .each(), which is used to iterate, exclusively, over a jQuery
object. The $.each() function can be used to iterate over any collection, whether it is a map (JavaScript object) or
an array. In the case of an array, the callback is passed an array index and a corresponding array value each time.
(The value can also be accessed through the this keyword, but Javascript will always wrap the this value as an
Object even if it is a simple string or number value.) The method returns its first argument, the object that was
iterated.
如有哪里写得不对,请大家指教~
个人有关JQuery插件的网站,请支持:jqueryhtml5.webege.com
相关文章推荐
- 深入理解jquery中的each用法
- jquery的each()函数用法
- jquery筛选数组之grep、each、inArray、map的用法及遍历son对象(转)
- 深入理解jQuery中$.get、$.post、$.getJSON和$.ajax的用法
- jquery each 用法
- jQuery $.each用法
- jquery中each用法
- 理解jQuery中$.get、$.post、$.getJSON和$.ajax的用法
- jquery中的each的几种用法
- jQuery中each的用法之退出循环和结束本次循环
- 深入理解jQuery中$.get、$.post、$.getJSON和$.ajax的用法
- jQuery中each的用法之退出循环和结束本次循环
- jquery中$.get和$.each中的理解
- jQuery $.each用法
- jQuery中each的用法
- jQuery中each的用法之退出循环和结束本次循环
- 深入理解jQuery中$.get、$.post、$.getJSON和$.ajax的用法
- jQuery中each的用法之退出循环和结束本次循环
- 深入理解jQuery中$.get、$.post、$.getJSON和$.ajax的用法
- jquery 遍历数组each的用法,还有一个jquery的基础用法