jq插件封装格式

(function($) {      // closure
    $.fn.hilight = function( options ) {  //将方法定义在$的fn上
        var defaults = {
            textColor: "#000",
            backgroundColor: "#fff"
        };
        var settings = $.extend( {}, defaults, options );
        return this.each(function() {
            // Plugin code would go here...
        });
    };
})(jQuery);

 使用

$(elem).hilight(options)
//或者
$.fn.hilight.call($(elem),options)
原文地址:https://www.cnblogs.com/gopark/p/10537331.html