我在ASP.NET的代码后端中使用JavaScript时遇到了问题,经过几个小时的研究,发现问题是转义字符引起的。
一开始我使用了这个。
这会产生JavaScript错误,因为“can't”中的引号需要使用转义字符,所以我使用了。
但它仍然不起作用。
最后我使用了。
“而且这很好。 我只是好奇为什么我们需要使用
一开始我使用了这个。
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "alert('Can't delete this data because it is bound with rate plan');", true);
这会产生JavaScript错误,因为“can't”中的引号需要使用转义字符,所以我使用了。
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);
“而且这很好。 我只是好奇为什么我们需要使用
\\'
而不是\'
才能使转义字符正常工作。”