<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <title>basic-demo</title> <script src="template-web.js"></script> </head> <body> <p id="content"></p> <script id="test" type="text/html"> {{if isAdmin}} <h1>{{title}}</h1> <ul> {{each list as value i}} <li>索引 {{i + 1}} :{{value}}</li> {{/each}} </ul> {{/if}} </script> <script> var data = { title: '基本例子', isAdmin: true, list: ['文艺', '博客', '摄影', '电影', '民谣', '旅行', '吉他'] }; var html = template('test', data); document.getElementById('content').innerHTML = html; </script> </body> </html>
相关推荐:
以上就是js中使用template模板引擎实现的一个例子(代码)的详细内容,更多请关注php中文网其它相关文章!
![php中文网直播班](https://img.php.cn/upload/course/000/000/071/621c239fc661a260.png)
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论