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全部內容了,希望大家多多支持~