A basic use of art

Source: Internet
Author: User

                {{ifISAdmin}} {Each list as value Index}}<li> Index:{{index}}:{{value}}</li>                          {{/Each }} </ul>                  {{/if}}                             <!--a Judgment statement--                                        {{ ifId==1}}                      12                     {{Else}}                        16                    {{/if}}            <!--judgment statement in one line--

var data={title:' HELLO World ', ISAdmin:true, list: [' News ', ' military ', ' history ', ' politics '], code:12, Name:"Can be joined", ID:1, }; var html= Template (' Test ', data); document.getElementById ("Content"). InnerHTML =html; </script> Escape does not escape HTML<div id= "Div_noescape" ><p> not escaped: <span style= "color: #F00" >hello world!</span></p> <p> default escape: &lt;span style= "color: #F00" &gt;hello world!&lt;/span&gt;</p></div> <script id= "No_escape" type= "text/html" > <p> not escaped: {{#text}}</p> &lt ;p > Default escape: {{text}}</p> </script> <script>var data_noescape={text:' <span style= ' color: #F00 ">hello world!</span>" }; var html_noescape= Template ("No_escape", Data_noescape); document.getElementById ("Div_noescape"). InnerHTML =Html_noescape; </script> storing templates in JavaScript<div id= "Div_complie" ><ur><li> index: 1: Movies </li><li> index: 2: TV series </li><li> index: 3: Arts </li><li> Index: 4: Music </li></ur></div> <script>var source= ' <ur> ' + ' {each list} ' + ' <li> index: {{$index +1}}:{{$value}}</ Li> ' + ' {{/each} ' + ' </ul> '; var data={list: [' Movies ', ' TV dramas ', ' Arts ', ' music '] }; var render=template.compile (source); var html=render (data); document.getElementById ("Div_complie"). InnerHTML =html; </script> embed child templates (include)<div id= "Div_include" ><ur><li> index: 1: Movies </li><li> index: 2: TV series </li><li> index: 3: Arts </li><li> Index: 4: Music </li></ur></div> <script id= "include" type= "text/html" >{{include' Test '}} </script> <script>document.getElementById ("Div_include"). InnerHTML =html; </script> Auxiliary Methods<script id= "helper" type= "text/html" >{{ time| XX: ' yyyy mm month dd Day HH:MM:SS '}} </script> <div id= "Div_helper" >2014 year August 20 20:12:51</div> <script>/*** Format the date, *@paramdate to format *@paramformat formatted pattern String * Supported pattern letters are: * y: Year, * M: Month of the year (1-1 2), * D: Day of the Month (1-31), * H: Hours (0-23), * M: minutes (0-59), * S: Seconds (0-59), * s: milliseconds (0-999), * Q: Quarter (1-4) * @returnString*/function DateFormat (date, format) {Date=Newdate (date); var map= { "M": Date.getmonth () + 1,//Month"D": date.getdate (),//Day"H": date.gethours (),//hours"M": date.getminutes (),//points"S": Date.getseconds (),//seconds"Q": Math.floor ((Date.getmonth () + 3)/3),//Quarterly"S": Date.getmilliseconds ()//milliseconds }; Format= Format.replace (/([YMDHMSQS]) +/g, function (all, t) {var v=Map[t]; if(v!==undefined) { if(All.length > 1) {v= ' 0 ' +v; V= V.substr (v.length-2); } returnv; } Else if(t = = = ' Y ') { return(Date.getfullyear () + "). substr (4-all.length); } returnAll ; }); returnformat; } var data={time:1408536771253, }; Template.helper ("XX", DateFormat); var html= Template (' helper ', data); document.getElementById (' Div_helper '). InnerHTML =html; //document.getElementById ("Div_helper"). InnerHTML = DateFormat (New Date ()); </script> </body>

A basic use of art

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.