JsRender系列demo(4)-if else
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <!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" /> <link href= "scripts/movielist.css" rel= "stylesheet" /> </head> <body> <h3>Using {{ if }} and {{ else }} to render conditional sections.</h3> <script type= "text/x-jsrender" id= "movieTemplate" > <tr> <td>{{>title}}</td> <td>{{ if languages}} Alternative languages:<em>{{>languages}}</em> {{ else subtitles}} Original language only... <br /> subtitles in <em>{{>subtitles}}</em> {{ else }} Original version only, without subtitles. {{/ if }}</td> </tr> </script> <script type= "text/javascript" > var movies = [ { title: "Meet Joe Black" , languages: "English and French" , subtitles: "English" }, { title: "Eyes Wide Shut" , subtitles: "French and Spanish" }, { title: "The Mighty" }, { title: "City Hunter" , languages: "Mandarin and Chinese" } ]; $( "#movieList" ).html($( "#movieTemplate" ).render(movies)); </script> </body> </html> |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步