源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

浅谈jquery中的each方法$.each、this.each、$.fn.each

  • 时间:2022-03-10 14:27 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:浅谈jquery中的each方法$.each、this.each、$.fn.each
jquery.each 方法 [b]方法一[/b]
$("img").each(function(i,elem){
 // i 下标 从零开始,
 // elem == this
 // $(elem).toggleClass("example");
 $(this).toggleClass("example");
});
[b]方法二[/b]
$.each([1,2,3,4],function(){
  //$(this)==数组中的每一个数组(如果数组是对象,就是对象)
});
[b]方法三[/b] 应有场景有点不一样
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全部内容了,希望大家多多支持编程素材网~
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部