在javascript中插入包含单引号的值

在javascript中插入包含单引号的值,javascript,Javascript,如何插入包含单引号的文本,而不是像这样以双引号传递 document.execCommand('insertHTML', false, 'Hello this is Veena's message'); 与几乎所有其他具有相似语法的语言(B、C、C++、C、java、……)一样,可以用反斜杠:< /P> document.execCommand('insertHTML', false, "Hello this is Veena's message"); 转义引号: document.exec

如何插入包含单引号的文本,而不是像这样以双引号传递

document.execCommand('insertHTML', false, 'Hello this is Veena's message');

与几乎所有其他具有相似语法的语言(B、C、C++、C、java、……)一样,可以用反斜杠:< /P>

document.execCommand('insertHTML', false, "Hello this is Veena's message");
转义引号:

document.execCommand('insertHTML', false, 'Hello this is Veena\'s message');
更多信息:

另一个选择是使用html字符代码

document.execCommand('insertHTML', false, 'Hello this is Veena\'s message');
在其前面使用反斜杠。这就行了。

不要引用:

document.execCommand('insertHTML', false, 'Hello this is Veena\'s message');

您应该用\

转义单引号。当前,我的字符串保存在android中的一个变量中。我将把这个变量发送到document.execCommand。在发送此变量之前,我必须调用String.replaceall(“'”,“\”);这对我不起作用。这就是我贴出这个问题的原因。有没有办法用转义序列替换单引号
document.execCommand('insertHTML', false, 'Hello this is Veena\'s message');
'Hello this is Veena\'s message'