-7

可能重复:
JavaScript 字符串中的双引号

var array=["famous quote by Shakespear is",""to be or not to be""]

如何在"用于分隔元素的数组的第二个元素中转义块引用?

4

2 回答 2

2

使用反斜杠:

var str = "famous quote by Shakespear is, \"to be or not to be\"";
var str = 'famous quote by Shakespear is, \'to be or not to be\'';

或者只是混合引号的类型:

var str = "famous quote by Shakespear is, 'to be or not to be'";
var str = 'famous quote by Shakespear is, "to be or not to be"';
于 2013-01-12T17:31:31.240 回答
2

您可以使用反斜杠转义或在字符串周围使用单引号:

var array=["famous quote by Shakespear is","\"to be or not to be\""];
var array=["famous quote by Shakespear is",'"to be or not to be"'];

只要正确配对,单引号和双引号是可以互换的。

于 2013-01-12T17:32:32.907 回答