node.js node js ejs 模板循环 jquery ejs 笔记
<% %> //解析js代码
<% for(var i=0; i<4; ++i) { %>
<% if(i==2){ break; }%>
<p><a href=#"><%= i %>this is a link!</a> </p>
<% } %>
<%= code %> //不解析html标签,直接输出html标签
<%- code %> //解析html标签
循环结果

js和css的获取,都要放在指定目录
<link rel="stylesheet" type="text/css" href="/1.css" /> <script src="/javascripts/ejs.min.js"></script>
引入其他模板
<%- include foot %> //引入foot.ejs
json ajax get
<script src="/javascripts/ejs_production.js"></script>
<script type = "text/javascript" >
function myfunction(){
var data='{"title":"cleaning","supplies":["mop","broom","duster"]}';
var html = new EJS({url: './mm/cleaning.ejs'}).render(JSON.parse(data));
document.getElementById("div1").innerHTML=html;
}
</script>
<button onclick = "myfunction()" >点击</button> <div id="div1"></div>
.\public\mm\cleaning.ejs 内容已经存放的目录 <h1><%= title %></h1> <ul> <% for(var y=0;y<supplies.length;y++) { %> <li><a href='<%= supplies[y] %>'><%= supplies[y] %></a> </li> <% } %> </ul>