1、没有参数

$("img").each(function(){
  $(this).toggleClass("example");
});

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

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

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; 
     } 
   });
});

相关文章:

  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2021-10-22
  • 2021-12-25
  • 2021-08-31
  • 2022-12-23
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
  • 2022-01-11
  • 2021-10-11
  • 2021-11-30
相关资源
相似解决方案