JS模板引擎是借助于工具把 js 数据转换成 html 需要的页面。art-template 是一个简约、超快的模板引擎,它采用作用域预声明的技术来优化模板渲染速度,从而获得接近 JavaScript 极限的运行性能,并且同时支持 NodeJS 和浏览器。但在使用前需要导入一个 js 文件:提取码:ad9h 。其使用方法为:
//声明
<script type=“text/html id=‘tpl’”></script>
//使用
var html=template(“tpl”,data);
具体详情见代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>创建和插入子元素-模板引擎法</title>
<script type="text/javascript" src="js/template-web.js" ></script>
<style type="text/css">
.content{
width:600px;
height: 400px;
border: 1px solid gray;
background: lightblue;
}
li{
list-style: