javascript - ASP.NET,JavaScript : silly annoying apostrophe problem

标签 javascript asp.net html-encode apostrophe

我想向我的 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/

相关文章:

javascript - 如何使用javascript在资源管理器中播放wav文件

javascript - 如何制作纯javascript实时搜索方法?

c# - Entity Framework 和 VARBINARY

javascript - 将值数据库传递给 Javascript

javascript - 引导日期选择器在月份选择 setDate 不起作用

javascript - 使用Dust.js(LinkedIn版本) `@eq`来匹配多个值

php - 为什么这不会解码为 html 实体?

asp.net - "<"在 ASP.NET 的文本框中 --> 如何允许它?

c# - ASP.NET Core 模型绑定(bind)和整数

c# - javascript 是否等效于 C#s HttpUtility.HtmlEncode?