码迷,mamicode.com
首页 > Web开发 > 详细

jquery中的each方法,$.each \ this.each \ $.fn.each

时间:2016-06-22 18:47:56      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

jquery.each 方法

方法一

$("img").each(function(i,elem){
 // i 下标 从零开始,
 // elem == this
 // $(elem).toggleClass("example");
$(this).toggleClass("example");
});
方法二
$.each([1,2,3,4],function(){
  //$(this)==数组中的每一个数组(如果数组是对象,就是对象)
});

方法三
应有场景有点不一样
this.each(function(){

})
扩展jQuery对象方法
应该是 jQuery.fn.Fun=function(){
  //this==$("img") 和下面的调用方法相结合,如果是其他对象就是其他对象
  this.each(function(){
  
  $(this)==$("img")[0],
  //$(this)==$("img")[1],
 // .......

  })
  

}
调用
$("img").Fun();


jquery中的each方法,$.each \ this.each \ $.fn.each

标签:

原文地址:http://www.cnblogs.com/tongchuanxing/p/5607954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!