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
| <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>原生js语法结构</title> <style> * { margin: 0; padding: 0; } ul, li { list-style: none; } </style> <script src="art-template/template-native.js"></script> <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript"> $(function () { var data={"name":"喵喵","age":"17","hobby":["哈哈","嘻嘻","啦啦"]}; var str = template("art1",data); console.log(str); $("#container").html(str); }); </script>
</head> <body> <div id="container"></div> <script type="text/html" id="art1"> <% if(name=="喵喵"){ %> <h2><%=name%></h2> <h2><%=age%></h2> <ul> <% for(var i=0;i< hobby.length;i++){ %> <li><%=i+1%><%=hobby[i]%></li> <%}%> </ul> <%}%> </script> </body> </html>
|