<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 >
{{#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>

 

相关文章:

  • 2021-11-02
  • 2022-12-23
  • 2021-07-07
  • 2021-09-27
  • 2022-03-09
猜你喜欢
  • 2021-08-27
  • 2021-05-10
  • 2022-12-23
  • 2022-03-09
  • 2022-01-08
相关资源
相似解决方案