Open zchfeng opened 2 years ago
var template = "我的名字{{name}},性别{{sex}},年龄{{age}}"; var data = { name: "jeck", sex: 1, }; function render(template, data) { return template.replace(/\{\{(\w+)\}\}/g, function (match, $1, index, str) { return data[$1]; }); } render(template, data)