星空网 > 软件开发 > Java

js之replace实现简单模板替换引擎

eg:

  var app={};

  app.tempEngine= (function () {
  var pattern = /\{(\w*[:]*[=]*\w+)\}(?!})/g;
  return function (template, json) {
  return template.replace(pattern, function (match, key, value) {
  return json[key];
     });
   }
})();

 

var template='<div>{name}</div>\

<div>{ege}</div>\

',data={

  name:"dabingzi",

      ege:28

}

 

$(app.tempEngine(template, data));

...../

...../

<div>dabingzi</div>\

<div>28</div>

 




原标题:js之replace实现简单模板替换引擎

关键词:JS

JS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

格丁尼亚海运:https://www.goluckyvip.com/tag/91985.html
海运新加坡海运费:https://www.goluckyvip.com/tag/91986.html
马来海运:https://www.goluckyvip.com/tag/91987.html
海运海运:https://www.goluckyvip.com/tag/91989.html
西马海运:https://www.goluckyvip.com/tag/91990.html
林查班海运:https://www.goluckyvip.com/tag/91991.html
去日本入住酒店,东西随意用却有一个特殊“要:https://www.vstour.cn/a/411241.html
中国有哪些著名的酒店品牌。:https://www.vstour.cn/a/411242.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流