1.

 1  插入特殊字符
 2 反斜杠用来在文本字符串中插入省略号、换行符、引号和其他相关javascript教程特殊字符。
 3 请看下面的 JavaScript 代码:
 4 var txt="We are the so-called "Vikings" from the north."
 5 document.write(txt)
 6 在 JavaScript 中,字符串使用单引号或者双引号来起始或者结束。这意味着上面的字符串将被截为:We are the so-called。
 7 要解决这个问题,就必须把在 "Viking" 中的引号前面加上反斜杠 (\)。这样就可以把每个双引号转换为字面上的字符串。
 8 var txt="We are the so-called \"Vikings\" from the north."
 9 document.write(txt)
10 现在 JavaScript 就可以输出正确的文本字符串了:We are the so-called "Vikings" from the north。
11 这是另一个例子:
12 document.write ("You \& me are singing!") 
13 上面的例子会产生以下输出:
14 You & me are singing!
15 下面的表格列出了其余的特殊字符,这些特殊字符都可以使用反斜杠来添加到文本字符串中:
16 代码 输出
17 \' 单引号
18 \" 双引号
19 \& 和号
20 \\ 反斜杠
21 \n 换行符
22 \r 回车符
23 \t 制表符
24 \b 退格符
25 \f 换页符
26 本节的内容是:在使用 JavaScript 进行编码的过程中,其他一些需要了解的重要事项。

 

posted on 2017-11-16 17:15  Sharpest  阅读(232)  评论(0编辑  收藏  举报