template.js模板工具案例

案例一

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8 
 9 <h1>THE MOST EXPECTED MOVIES IN 2085</h1>
10 <div id="haha">
11     <h3 style="color: #00f;"></h3>
12     <p style="color: #f00;">时间</p>
13     <p style="color: #0f0;">导演</p>
14     <p style="color: #00f;">主演</p>
15 </div>
16 
17 </body>
18 </html>
19 <script src="../js/sven.js"></script>
20 <script src="../js/template.js"></script>
21 <script id="movie1" type="text/html">
22     <h3 style="color: #00f;">{{name}}</h3>
23     <p style="color: #f00;">时间:{{time}}</p>
24     <p style="color: #0f0;">导演:{{director}}</p>
25     <p style="color: #00f;">主演:{{main}}</p>
26 </script>
27 <script>
28     var movie1 = {
29         name : 'Game of Throne',
30         time : '2084-2-56',
31         director : 'Monica Geller',
32         main : 'Chandler Bing'
33     };
34     var str1 = template('movie1',movie1);
35     document.getElementById('haha').innerHTML = str1;
36 </script>

 

posted @ 2017-03-01 09:30  ifIhaveWings  阅读(1871)  评论(0编辑  收藏  举报