我想在Javascript中用 \"
替换 "
。
我有:
text = text.toString().replace("\"", '\\"')
结果:
\\"
我想在Javascript中用 \"
替换 "
。
我有:
text = text.toString().replace("\"", '\\"')
结果:
\\"
试试这个:
text = text.toString().replace(/"/g, '\\"')
或者这样:
text = text.toString().replace('"', '\\"')
text = text.toString().replace(/\\"/g, '"').replace(/"/g, '\\"');
var text = JSON.stringify(JSON.stringify(text))
这个可以:
text = text.toString().replace("\"", '\\\"');
您基本上需要通过 \ 来转义 \ 和 "。