首页 > Web开发 > 详细

jQuery.each的function中有哪些参数(可以大概理解function中的参数问题)

时间:2016-07-21 00:45:07      阅读:207      评论:0      收藏:0      [点我收藏+]

1、没有参数

$("img").each(function(){
  $(this).toggleClass("example");
});
  • 1
  • 2
  • 3

2、有一个参数,这个参数为index

$("img").each(function(i){
   this.src = "test" + i + ".jpg";
 });
  • 1
  • 2
  • 3

3、有两个参数,第一个参数为index,第二个参数为dom元素本身

$("button").click(function () { 
$("div").each(function (index, domEle) { 
  // domEle == this 
  $(domEle).css("backgroundColor", "yellow");  
  if ($(this).is("#stop")) { 
  $("span").text("Stopped at div index #" + index); 
  return false; 
  } 
});
});

jQuery.each的function中有哪些参数(可以大概理解function中的参数问题)

原文:http://www.cnblogs.com/beijingstruggle/p/5690133.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!