我只是遇到了javascript問題,我使用的是asp.net上的代碼,經過幾個小時的計算後,成爲逃避角色的問題。爲什麼在字符串中使用javascript轉義字符的引號需要是\'而不是'
起初我用這個。
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "alert('Can't delete this data because it is bound with rate plan');", true);
這將使javascript錯誤,因爲在「不能」的引用需要使用轉義字符,所以我使用。
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "alert('Can\'t delete this data because it is bound with rate plan');", true);
但它仍然不起作用。
最後我用
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "alert('Can\\'t delete this data because it is bound with rate plan');", true);
,這是罰款。
我只是好奇,爲什麼我們需要使用\\'
而不是\'
爲了使轉義字符正常工作。
謝謝您的詳細解釋,我會在這個問題上更加小心。 – 2011-05-02 10:03:37