例如:
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) 【正确】
js特殊字符转义
点的转义:. ==>\\u002E
美元符号的转义:$ ==>\\u0024
乘方符号的转义:^ ==>\\u005E
左大括号的转义:{ ==>\\u007B
左方括号的转义:[ ==>\\u005B
左圆括号的转义:( ==>\\u0028
竖线的转义:| ==>\\u007C
右方括号转义:] ==>\\u005D
右圆括号的转义:) ==>\\u0029
星号的转义:* ==>\\u002A
加号的转义:+ ==>\\u002B
问号的转义:? ==>\\u003F
反斜杠的转义:\ ==>\\u005C
JScript 提供了一些特殊字符,允许在字符串中包括一些无法直接键入的字符。每个字符都以反斜杠开始。反斜杠是一个转义字符,表示 JScript 解释器下面的字符为特殊字符。转义序列 字符
\b 退格
\f 走纸换页
\n 换行
\r 回车
\t 横向跳格 (Ctrl-I)
\' 单引号
\" 双引号
\\ 反斜杠
请注意,由于反斜杠本身用作转义符,因此不能直接在脚本中键入一个反斜杠。如果要产生一个反斜杠,必须一起键入两个反斜杠 (\\)。
document.write('The image path is C:\\webstuff\\mypage\\gifs\\garden.gif.')
document.write('The caption reads, "After the snow of \'97. Grandma\'s house is covered."')