Home > Web Front-end > JS Tutorial > Introducing the usage examples of jquery.mustache.js

Introducing the usage examples of jquery.mustache.js

零下一度
Release: 2017-06-17 17:53:35
Original
2882 people have browsed it

jquery.mustache is encapsulated with jQuery and provides the following methods to make template use more convenient.
1, three ways to add templates

add,

addFromDom

addFromString

You can add templates directly, whether as String Text or reference to other DOM elements

(1) template is a string literal

//add仅仅是把template添加到当前页面,注意并没有渲染
$.Mustache.add('string-template', '<p>Hi, {{name}}, this is an inline template<p>');
Copy after login

(2) Reference to DOM element addFromDom

// 两者是相同的,后者有更简洁的语法 These two are identical, the latter just provides a terser syntax.
$.Mustache.add('dom-template', $('#dom-template').html());
$.Mustache.addFromDom('dom-template');
Copy after login

If you prefer to store the templates in the DOM (assuming they are loaded from an external file), then you can just call

$.Mustache.addFromDom() without any parameters, that way Will read all

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template