這篇文章主要介紹了jQuery聚合函數,實例分析了jQuery中聚合函數的使用方法,需要的朋友可以參考下
本文實例講述了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程序設計有所幫助。
新聞熱點
疑難解答
圖片精選