javascript 怎么把字符串中的特殊符号转义

2025-03-07 00:22:02
推荐回答(3个)
回答1:

js中的特殊字符,加上转义符\ 。
例如:
var txt="We are the so-called "Vikings" from the north." document.write(txt) 【错误】
var txt="We are the so-called \"Vikings\" from the north." document.write(txt) 【正确】

回答2:

\就是js里的转义符

回答3:

可以用replace 替换