我想用str_replace
或者其他类似的替代方法替换JavaScript中的一些文本。如何在JavaScript中执行str_replace,替换JavaScript中的文本?
var text = "this is some sample text that i want to replace";
var new_text = replace_in_javascript("want", "dont want", text);
document.write("new_text");
应该给
this is some sample text that i dont want to replace
奇怪没人注意到,PHP的'str_replace'也接受相同的长度,其中,所述第一阵列中的每个串置换为相同的索引在所述第二阵列中的字符串的两个阵列。请参阅http://stackoverflow.com/a/5069776/296430,了解迄今为止我发现的唯一正确功能,该功能模仿JavaScript中的确切行为。 – 2013-09-02 00:08:42
@JulesColle经常失败的答案 - 看看为什么/当它失败和更好的解决方案在这里:http://stackoverflow.com/a/37949642/445295 – 2016-06-21 16:24:32