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)

 

posted @ 2019-03-15 15:22  极客小乌龟  阅读(229)  评论(0编辑  收藏  举报