我是靠谱客的博主 落后微笑,这篇文章主要介绍DOT.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> div{ font-family: "微软雅黑"; font-size: 18px; line-height: 23px; text-align: center; width: 485px; margin: 0 auto; } .jishu{ background: orange; } .oushu{ background: yellow; } table td{ padding: 5px 44px; border: 1px solid #f36; } thead tr{ background: #102b6a; color: white; } </style> </head> <body> <div > </div> <script src="../jquery-1.11.0.min.js"></script> <script src="../doT.min.js"></script> <!-- 将类型设置为template,标识为doT.JS --> <script type="template" id="dotTmpl"> <table> <thead> <tr> <th>姓名</th> <th>性别</th> <th>入学日期</th> </tr> </thead> <tbody> {{ for(var i=0;i<it.length;i++){ }} <tr {{ if( i%2 == 0){ }} class="jishu" {{ }else{ }} class="oushu" {{ } }}> <td>{{=it[i].name}}</td> <td>{{=it[i].sex}}</td> <td>{{=it[i].date}}</td> </tr> {{ } }} </tbody> </table> </script> <script> // 数据 var data = [ {"name":19,"sex":"男","date":"1991年12月21日"}, {"name":19,"sex":"男","date":"1991年12月21日"}, {"name":19,"sex":"男","date":"1991年12月21日"}, {"name":19,"sex":"男","date":"1991年12月21日"}, {"name":19,"sex":"男","date":"1991年12月21日"} ] // 通过dot.template调用你所写的dot.JS。 var tmpl = doT.template($("#dotTmpl")[0].text); // 将数据扔进templ中。并在DIV中显示出来 $("div").html(tmpl(data)); </script> </body> </html>


模板引擎可以让(网站)程序实现界面与数据分离,这就大大提升了开发效率,良好的设计也使得代码重用变得更加容易。

最后

以上就是落后微笑最近收集整理的关于DOT.js 实例的全部内容,更多相关DOT.js内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(69)

评论列表共有 0 条评论

立即
投稿
返回
顶部