废话不多说,主要是利用正则表达式replace+eval动态取值(纯属娱乐) String.prototype.myReplace = function(){ return this.replace(/\$\{([^}]*)\}/g,function(metched,key){ return eval(key) }) } var name = '张三',age = '20'; var userTxt = '${name}今年${age}岁了' ) 来源:https://www.cnblogs.com/angfl/p/11928292.html 标签 es5 eval var