<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="js/mb.js" type="text/javascript" charset="utf-8"></script> <script src="js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script> <title></title> </head> <body> <div id="div_complie"> </div> <script id="l" type="text/html"> {{each $data}} <span style="display: inline-block;margin:0rem 50px;" > {{$value}} </span> {{/each}} <div id="erji"></div> </script> <script> var nav=[1,2,3,4] var list=template("l",nav) document.getElementById("div_complie").innerHTML = list; $("span").click(function(){ var source = '<ur>' + '{{each list}}'+ '<li>索引:{{$index+1}}:{{$value}}</li>'+ '{{/each}}'+ '</ul>'; var data = { list : ['电影','电视剧456','综艺','音乐'] }; var render = template.compile(source); var html = render(data); $("#erji").append(html) }) </script> </body> </html>