`
598751848
  • 浏览: 670 次
  • 性别: Icon_minigender_1
  • 来自: 大连
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

笔记——插入特殊字符

阅读更多
插入特殊字符
反斜杠用来在文本字符串中插入省略号、换行符、引号和其他特殊字符。

请看下面的 JavaScript 代码:

var txt="We are the so-called "Vikings" from the north."
document.write(txt)在 JavaScript 中,字符串使用单引号或者双引号来起始或者结束。这意味着上面的字符串将被截为:We are the so-called。

要解决这个问题,就必须把在 "Viking" 中的引号前面加上反斜杠 (\)。这样就可以把每个双引号转换为字面上的字符串。

var txt="We are the so-called \"Vikings\" from the north."
document.write(txt)现在 JavaScript 就可以输出正确的文本字符串了:We are the so-called "Vikings" from the north。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics