标签:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <div class="box"></div> <script type="text/template" id="xjj"> <ul> <% for(var i = 0 ; i < list.length ; i ++){%> <li>我的名字是:<b><%=list[i].name%></b>我的年龄是:<b><%=list[i].age%></b>。</li> <%};%> </ul> </script> <script src="js/template-native.js"></script> <script> /*准备数据*/ var data = { list:[ {name:‘xjj1‘,age:10}, {name:‘xjj2‘,age:12}, {name:‘xjj3‘,age:16}, {name:‘xjj4‘,age:40} ] } /*解析数据成html {model:‘‘}*/ var html = template(‘xjj‘,data); document.querySelector(‘.box‘).innerHTML = html; </script> </body> </html>
标签:
原文地址:http://www.cnblogs.com/lsy0403/p/5932296.html