我想向我的 ImageButton 添加一个确认框,所以我有以下内容:
btn.Attributes.Add("onclick", "return confirm('OK to delete this district from the consultant\'s list?');");
但是 .NET 对整个内容进行 html 编码,使其在 HTML 中显示为:
onclick="return confirm('OK to delete this district from the consultant's list?');"
因此“consultant's”中的撇号看起来与确认参数周围的撇号相同,并且 JavaScript 变得很困惑,并且确认框不会出现。
删除“顾问”的撇号解决了问题,但随后我遇到了一个更烦人的标点错误,这是 Not Acceptable 。
我似乎需要的是撇号的“javascript”转义,它只会为 javascript 转义撇号,而不是为 HTML ..如果这有意义的话。
有什么想法吗?
最佳答案
btn.Attributes.Add("onclick", "return confirm(\"OK to delete this district from the consultant\'s list?\");");
转义"
并使用confirm("...")
关于javascript - ASP.NET,JavaScript : silly annoying apostrophe problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4834461/