我只是遇到了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