<!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>
时间: 2024-10-29 19:11:16