Home > Web Front-end > JS Tutorial > 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

高洛峰
Release: 2016-12-29 10:50:38
Original
1918 people have browsed it

jquery.each method

Method one

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

Method two

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

Method three

The scene should be a little different

this.each(function(){
 
})
Copy after login

Extended jQuery object method

should be

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

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!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template