jQuery聚合函数实例

时间:2015-05-21    点击:51   

本文实例讲述了jQuery聚合函数。分享给大家供大家参考。具体如下:

(function($) {
  $.fn.aggregate = function(seed, func) {
    var _r = seed == null ? "" : seed;
    this.each(function(index, element) {
      _r = func(_r, element);
    });
    return _r;
  };
  $.fn.count = function() {
    return 
      this.aggregate( 0, // seed
      function(result, _) { // func
        return result + 1;
      });
  };
})(jQuery);
alert($("a").count());

希望本文所述对大家的jQuery程序设计有所帮助。

JavaScript检测鼠标移动方向的方法
jQuery实现强制cookie过期方法汇总
jQuery判断指定id的对象是否存在的方法
jQuery实现转动随机数抽奖效果的方法
JQuery分屏指示器图片轮换效果实例
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved