js中怎么表示转义符

JavaScript06

js中怎么表示转义符,第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) 【正确】

转义符的意思是读取后面\后面的东西为字符串

上面这段翻译过来是

<img id="imgkin这里是你的i值" src="Images/skin/c这里是你的i值_1.gif" width="12" height="12" alt="" onclick="setSkin这里是你的i值" />

加入反斜杠的目的是为了不和外面的字符重叠 引起歧义

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