jQuery插件

jQuery提供了两个用于扩展jQuery功能的方法,jQuery.fn.extend()和jQuery.extend();

;$(function($){
    //用于扩展方法
    $.fn.extend({
        "color":function(value) {
            return this.css("color", value);
        }
    });
})(jQuery);

$("p").color();

jQuery.extend();

用于设置默认参数,或全局函数

;$(function($){
    $.extend({
        ltrim : function (text) {
            return (text || "").replace(/^\s+/g, "");
        }
    });
})(jQuery);
function foo(options) {
    options = jQuery.extend({
        name:"bar",
        length="5"
    }, options);
};


你可能感兴趣的:(jQuery插件)