Last active
December 7, 2015 02:16
-
-
Save iBaozi/9e6ada1ac2695ad12302 to your computer and use it in GitHub Desktop.
js javascript 模板
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 模板 | |
var floorTpl = '<div class="others" data-id="{id}">' + | |
'<span class="nick">{nick}</span>' + | |
'<span class="date">{datelineStr}</span>' + | |
'<div class="ctt">' + | |
'{content}' + | |
'<a href="javascript:void(0)"> [回复]</a>' + | |
'</div>' + | |
'</div>'; | |
function tplRender(tpl, dataObj) { | |
return tpl.replace(/\{(\w+)\}/g, function ($0, $1) { | |
return dataObj[$1]; | |
}); | |
} | |
var data = { | |
nick: '包子', | |
datelineStr: '3月2日', | |
content: '今天天气不错' | |
} | |
var html = tplRender(floorTpl, data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment