/**
* 应用对象替换模板内容
* templ({name:'Rock'},'<html><title>{name}</title></html>');
* st:0,1:未找到属性是是否保留
*/
templ: function(obj, str, st) {
return str.replace(/\{([\w_$]+)\}/g, function(c, $1) {
var a = obj[$1];
if (a === undefined || a === null) {
if (st === undefined) return '';
switch (st) {
case 0:
return '';
case 1:
return $1;
default:
return c;
}
}
return a;
});
}
您可能感兴趣的文章: