首页 > Web开发 > 详细

javascript插件编写小结

时间:2014-01-20 08:55:34      阅读:414      评论:0      收藏:0      [点我收藏+]

      写JS插件,最好是先通过HTML方式将展示结果显示出来,然后再封装成JS插件,将其画出来。JS模板如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(function($){
   $.fn.fnName = function(options){
      var opts = $.extend({},$.fn.fnName.Defaults,options);
      return this.each(function(){
          var $window;
          CreateTemplate(this); // 创建模板,也就是拼接一个界面
          SetStyleForTemplate(); // 给模板添加样式
          SetEventForTemplate(); //添加事件
 
      function CreateTemplate(w){
             $window = $(w);
             var arrcontent = [];
             arrcontent.push("*********");
             *************************** //拼接
             CreateSubTemplate(arrcontent);//分支拼接,特殊情况利于层次分明
 
             $window.html(arrcontent.join(""));
             arrcontent = null;
          }
 
      functon CreateSubTemplate(arrcontent){
         arrcontent.push("*********");
          }
 
      function SetStyleForTemplate(){
             $window.find("***")*************;//设置样式
          }
 
          function SetEventForTemplate(){
             $window.find("***")************;//添加事件
          }
      });
   };
   $.fn.fnName.Defaults ={
   // 默认参数
   };
})(jQuery);

  

javascript插件编写小结

原文:http://www.cnblogs.com/kinger906/p/3526263.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!