You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vartpl=['{{name}}','<p>我来自{{address}}</p>','<p>这是我的个人博客</p>',].join("");vardata={name: "<h1>你好</h1>",address: '湖北襄阳'}functionhtmlTpl(tpl,data){returntpl.replace(/{{(\w+)}}/g,function(){returndata[arguments[1]];});}// var html = tpl.replace(/{{name}}/, data.name).replace(/{{address}}/, data.address);document.body.innerHTML=htmlTpl(tpl,data)
这像什么,模板赋值啊,忽然发现一个新大陆,有意思
现在我把它改进了下
顺便说一下,正则的确是很好的工具,有了正则,思路又开阔了些
预览一下
#2016-07-28
The text was updated successfully, but these errors were encountered: