2020-04-29 js特殊常用字符转义

JavaScript09

2020-04-29 js特殊常用字符转义,第1张

js特殊字符转义

点的转义:. ==>\\u002E

美元符号的转义:$ ==>\\u0024

乘方符号的转义:^ ==>\\u005E

左大括号的转义:{ ==>\\u007B

左方括号的转义:[ ==>\\u005B

左圆括号的转义:( ==>\\u0028

竖线的转义:| ==>\\u007C

右方括号转义:] ==>\\u005D

右圆括号的转义:) ==>\\u0029

星号的转义:* ==>\\u002A

加号的转义:+ ==>\\u002B

问号的转义:? ==>\\u003F

反斜杠的转义:\ ==>\\u005C

在js中遇到引号,括号等字符的时候需要用到转义符:\

例如:“hello “world””里面有两个上双引号,这个在js里面会有歧义,应该如下书写

“hello \"world\"”就ok了

即在引号前面加一个\

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) 【正确】