本文介绍了template.js前端模板引擎使用,分享给大家,具体如下:
下载地址:https://github.com/yanhaijing/template.js
作者编写的文档:https://github.com/yanhaijing/template.js/blob/master/README.md
源码学习
快速上手
编写模板
使用一个type=”text/html”的script标签存放模板,或者放到字符串中:
rush:js;">
渲染模板
rush:js;">
var tpl = document.getElementById('tpl').innerHTML;
template(tpl,{list: [{name: "yan"},{name: "haijing"}]});
输出:
rush:xhtml;">
- yan
- haijing
转义
rush:js;">
rush:js;">
注册函数
rush:js;">
<script id="tpl" type="text/html">
<%:up='yanhaijing'%>
<div id="wp">
<script id="tpl" type="text/html">
<%:up='yanhaijing'%>