2013-02-27 75 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'