function Tp(temp, dataarry) {
return temp.replace(/\$\{([\w]+)\}/g, function(s1, s2) { var s = dataarry[s2]; if (typeof (s) != "undefined") { return s; } else { return s1; } });
}
return temp.replace(/\$\{([\w]+)\}/g, function(s1, s2) { var s = dataarry[s2]; if (typeof (s) != "undefined") { return s; } else { return s1; } });
}
给你个w3school的看看吧
return temp.replace(/\$\{([\w]+)\}/g, function(s1, s2) {
var s = dataarry[s2];
if (typeof (s) != "undefined") {
return s;
} else {
return s1;
}
});
}
谢谢,不过你的意思我没看太懂,但是s2应该是指正则表达式匹配到的内容在temp中出现的位置,相当于indexof