写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); |
原文:http://www.cnblogs.com/kinger906/p/3526263.html