jQuery 插件开发

一般jQuery 插件的开发的类型主要有三种,分别是以下三种:

1. jQuery 方法

2. 全局函数

2. 选择器(这种太难了,暂时没有办法自己开发)

为了不让种插件产生冲突,一般是采取闭包的方式来开发,下面是闭包开发插件的基本格式

下面是开发jQuery 的方法插件的基本格式

(function ($) {
    $.extend($.fn, {
    })
})(jQuery)

下面是开发全局函数的基本格式

(function ($) {
    $.extend($, {
    })
})(jQuery)

当然你如果你少用的话,直接用原型也可以,如下面的实例

    jQuery.fn.extend({ test: function () {
        var _this = this;
        alert(this[0].nodeName);
        return _this;
    }
    });

下面是标准开发的实例,全局函数,比较最少值及最大值

        (function ($) {
            $.extend($, {
                minValue: function (a, b) {
                    return a > b ? b : a;
                }
                ,
                maxValue: function (a, b) {
                    return a > b ? a : b;
                }
            })
        })(jQuery)