<html>
<head>
<title>handlebars.js 模板引擎</title>
<link href="https://cdn.bootcss.com/vis/4.21.0/vis.min.css" rel="stylesheet">
<style type="text/css">
</style>
</head>
<body>
<script id="tpl" type="text/x-handlebars-template">
{{#each data}}
<div>
<h1>{{title}}</h1>
<div>{{content}}</div>
</div>
{{/each}}
</script>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.js"></script>
<script src="https://cdn.bootcss.com/handlebars.js/4.0.11/handlebars.min.js"></script>
<script>
$(function () {
var tpl = $("#tpl").html();
var template = Handlebars.compile(tpl);
var context = {
data: [
{title: "xutongbao", content: "javascript"},
{title: "徐同保", content: "CSS3"}
]
};
var html = template(context);
$('body').html(html);
});
</script>
</body>
</html>