【实例截图】
【核心代码】
<!DOCTYPE html> <html> <head> <title>Mustacheo</title> <link rel='stylesheet', href='./css/application.css' type='text/css' /> <link rel='stylesheet', href='./css/default.css' type='text/css' /> <link rel='stylesheet', href='./css/github.css' type='text/css' /> <script src="./js/jquery-1.7.1.min.js" type="text/javascript"></script> <script src="./js/jquery.mustache.js" type="text/javascript"></script> <script src="./js/highlight.pack.js" type="text/javascript"></script> <script src="./js/application.js" type="text/javascript"></script> </head> <body> <div id="container"> <h1>}</h1> <h2>About Templates</h2> <p>A mustache template is a string that contains mustache tags. Tags are indicated by the <b>double mustaches</b> that surround them. {{person}} is a tag, as is {{#person}}. In both examples we refer to person as the tag's <b>key</b>.</p> <p>The most basic tag type is a simple variable. A {{name}} tag renders the value of the name key in the current context. If there is no such key, <b>nothing is rendered.</b></p> <p>All variables are HTML-escaped by default. If you want to render unescaped HTML, use the triple mustache: {{{name}}}. You can also use & to unescape a variable.</p> <p>Comments begin with a bang and are ignored. The following template: Today{{! ignore me }}.</p> <div class="code-section"> <h2>Basic Template</h2> <p>Takes two parameters: 1) the mustache template and 2) a view object that contains the data</p> <pre> <code> var view = { title: "Joe", calc: function () { return 2 4; } }; var template = "{{title}} spends {{calc}}" var output = $.mustache(template, view); </code> </pre> <h3>Result</h3> <div class="result"> </div> </div> <div class="code-section"> <h2>Basic Template with Dot-Notation</h2> <p>Takes two parameters: 1) the mustache template and 2) a view object that contains the data</p> <pre> <code> var view = { title: "Survivor", author: {first: "Chuck", last: "Palahniuk"} }; var template = "{{title}} written by {{author.first}} {{author.last}}" var output = $.mustache(template, view); </code> </pre> <h3>Result</h3> <div class="result"> </div> </div> </div> </body> </html>