1

我想在我的 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?');" 

因此“顾问”中的撇号看起来与确认参数周围的撇号相同,并且 javascript 变得很混乱,并且确认框不会出现。

删除“顾问的”撇号解决了这个问题,但是我有一个更烦人的标点错误,这是不可接受的。

我似乎需要的是撇号的“javascript”转义,它只会为 javascript 转义撇号,而不是 HTML .. 如果这有意义的话。

有任何想法吗??

4

1 回答 1

0
btn.Attributes.Add("onclick", "return confirm(\"OK to delete this district from the consultant\'s list?\");");

逃生"和使用confirm("...")

于 2011-01-29T01:21:29.543 回答