可能重复:
JavaScript 字符串中的双引号
var array=["famous quote by Shakespear is",""to be or not to be""]
如何在"
用于分隔元素的数组的第二个元素中转义块引用?
可能重复:
JavaScript 字符串中的双引号
var array=["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'";
var str = 'famous quote by Shakespear is, "to be or not to be"';
您可以使用反斜杠转义或在字符串周围使用单引号:
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"'];
只要正确配对,单引号和双引号是可以互换的。