码迷,mamicode.com
首页 > Web开发 > 详细

JsRender系列demo(2)多模板-template

时间:2014-07-27 22:00:09      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/jquery-ui.js"></script>
<script type="text/javascript" src="scripts/jsrender.js"></script>
<link href="scripts/demos.css" rel="stylesheet" />
</head>
<body>
<button id="switchBtn">展示详细内容</button><br />
<table>
<tbody id="movieList"></tbody>
</table>

<script type="text/javascript">
//数据来源
var movies = [
{ name: "Cupid", Birthday: "1998-12-12", nation: "中国" },
{ name: "陌上花开", Birthday: "1999-23-234", nation: "美国" },
{ name: "Tina", Birthday: "1976-34-13", nation: "法国" }
];
//两个模板
$.templates({
titleTemplate: "<tr><td colspan=3>{{>name}}</td></tr>",
detailTemplates: "<tr><td>姓名:{{>name}}</td><td>出生日期:{{>Birthday}}</td><td>国籍:{{>nation}}</td></tr>"
});
var details = true;
//多模板
function switchTemplates() {
var html, button = $("#switchBtn");
details = !details;
if (details) {
//第一个木板
button.text("展示姓名");
html = $.render.detailTemplates(movies);
} else {
//第二个某班
button.text("展示详细信息");
html=$.render.titleTemplate(movies);
}
$("#movieList").html(html);
}
$("#switchBtn").click(switchTemplates);
switchTemplates();
</script>
  


</body>
</html>

  

JsRender系列demo(2)多模板-template

标签:

原文地址:http://www.cnblogs.com/alphafly/p/3871305.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!