本文实例讲述了javascript模板引擎用法。分享给大家供大家参考。具体如下:
这里介绍的这个模板引擎写得短小精悍,非常值得一看
tmpl.js文件如下:
// Simple JavaScript Templating
// John Resig - http://ejohn.org/ - MIT Licensed
(function() {
var cache = {};
this.tmpl = function tmpl(str, data) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn =
!/W/.test(str)
?
cache[str] = cache[str] || tmpl(document.getElementById(str).innerHTML)
:
// Generate a reusable function that will serve as a template
// generator (and which will be cached).
new Function(
"obj", "var p=[],print=function(){p.push.apply(p,arguments);};" +
// Introduce the data as local variables using with(){}
"with(obj){p.push('" +
// Convert the template into pure JavaScript
str
.replace(/[
]/g, " ")
.split(")[^ ]*)'/g, "$1
")
.replace(/ =(.*?)%>/g, "',$1,'")
.split(" ")
.join("');")
.split("%>")
.join("p.push('")
.split("
")
.join("\'") +
"');}return p.join('');"
); // Function ends
// Provide some basic currying to the user
return data ? fn(data) : fn;
};
})();index.html文件如下:
多奥淘宝客程序免费版拥有淘宝客站点的基本功能,手动更新少,管理简单等优点,适合刚接触网站的淘客们,或者是兼职做淘客们。同样拥有VIP版的模板引擎技 术、强大的文件缓存机制,但没有VIP版的伪原创跟自定义URL等多项创新的搜索引擎优化技术,除此之外也是一款高效的API数据系统实现无人值守全自动 化运行的淘宝客网站程序。4月3日淘宝联盟重新开放淘宝API申请,新用户也可使用了
0
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号