Home  >  Article  >  Web Front-end  >  A brief discussion on the each method $.each, this.each, $.fn.each in jquery

A brief discussion on the each method $.each, this.each, $.fn.each in jquery

高洛峰
高洛峰Original
2016-12-29 10:50:381885browse

jquery.each method

Method one

$("img").each(function(i,elem){
 // i 下标 从零开始,
 // elem == this
 // $(elem).toggleClass("example");
 $(this).toggleClass("example");
});

Method two

$.each([1,2,3,4],function(){
  //$(this)==数组中的每一个数组(如果数组是对象,就是对象)
});

Method three

The scene should be a little different

this.each(function(){
 
})

Extended jQuery object method

should be

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

The above is a brief discussion of the each method $.each and this.each in jquery brought to you by the editor , all the contents of $.fn.each, I hope everyone will support the PHP Chinese website~

Please pay attention to more related articles about the each method in jquery $.each, this.each, $.fn.each PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn