2013-02-27 25 views
-2
document.execCommand('insertHTML', false, 'Hello this is Veena's message'); 

我怎样才能插入包含比几乎所有其他语言具有类似的语法通过它在双引号像插入包含在JavaScript中单引号的值

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

回答

2

至于其他单引号的文本( B,C,C++,C#,Java的,...),你可以用一个反斜杠逃脱'

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

逃离报价:

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

更多信息:http://www.quackit.com/javascript/tutorial/javascript_escape_characters.cfm

另一种选择,是使用HTML字符代码它。

document.write('veena&#39s'); 
+0

目前我的字符串保存在Android的一个变量逃脱单引号。我将发送这个变量到document.execCommand。在发送这个变量之前,我必须调用String.replaceall(“'”,“\'”);这不适合我。这就是我发布这个问题的原因。有什么方法可以用换码顺序替换单引号 – 2013-02-27 08:27:18

+0

我会用另一种可能性编辑它。 – Bernie 2013-02-27 08:32:22

+0

谢谢...'veena''正在为我工​​作......非常感谢... – 2013-02-27 08:59:45

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

使用前反斜杠。这将起作用。

+0

这不是一个斜线。 – 2013-02-27 08:24:36

1

逃离报价:

'Hello this is Veena\'s message'