jquery 插件封装总结

来源:互联网 发布:java字符流写入文件 编辑:程序博客网 时间:2024/05/06 12:24

总结了下网上文章:

菜鸟总结,求大神指正,一定尽力改

封装插件的类型主要分3类:

1.封装对象(比较常用)

2.封装全局函数(一般)

3.封装选择器(不常用)

下面一个一个介绍下面

通用模版

;(function($){            $.fn.hilight=function(options){                var defaults={                    foreground:'red',                    background:'yellow'                    };                var opts = $.extend(defaults,options);                //dosomethings            };        })(jQuery);


1.封装对象


;(function($){$.extend({"函数名":function(自定义参数){//这里写插件代码}});})(jQuery);或者;(function($){$.函数名=function(自定义参数){//这里写插件代码}})(jQuery);


 2.封装全局函数

;(function($){$.extend({ltrim:function(text){return (text||"").replace(/^\s+g,"");},rtrim:function(text){return (text||"").replace(/\s+$/g,"");}});})(jQuery);或者;(function($){$.ltrim=function(text){return (text||"").replace(/^\s+g,"");},$.rtrim=function(text){return (text||"").replace(/\s+$/g,"");}})(jQuery);

3.封装选择器

…………

0 0
原创粉丝点击