我的应用程序中的 html 文本有问题。场景是,我可以将输入到编辑器(在我的情况下为 radeditor)中的文本保存到 xml 属性中。在保存的同时,我确实喜欢,
Server.HtmlEncode(EditorGuidance.Content.Trim)
在我的代码的其他部分中,我需要从后面的代码中创建一个图像,并附加一个 onclick javascript 事件,将为此指导字段保存的值传递给 js 方法。
我喜欢,
Dim desc As String = control.Descendants("controlGuidance").First().Attribute("description").Value
lblGuidanceImage.Text = "<img onCliCk=""DisplayControlHelp('" & HttpUtility.HtmlDecode(desc.Replace("\", "\\").Replace("'", "\'")) & "')"" style=""vertical-align:middle; padding-right:2px; cursor: pointer;"" src=""../Images/help.gif"" alt=""Click for additional guidance"" title=""Click for additional guidance"" /> "
现在,我编写的 js 方法必须在该页面中获取 radwindow 并在该窗口中显示传递的文本。
function DisplayControlHelp(helpText) {
var wnd = $find("<%=RdWndGuidance.ClientID %>");
var controlGuidance = document.getElementById("<%= lblControlGuidance.ClientID %>");
helpText = $("<div/>").text(helpText).html();
controlGuidance.innerHTML = helpText;
wnd.show();
}
现在,这适用于其中没有 html 标签的文本。
但这失败(图像被呈现到页面,但点击事件不起作用)对于文本
<p style="list-style-type: none; font-size: 15px; font-family: Georgia, Century, Times, serif; color: #333333; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 15px; line-height: 21px; padding-right: 0px;border: 0px;">Around 3,000 patients died needlessly last year as a result of poor care, and nearly half a million were harmed unnecessarily in the NHS,<a href="http://www.huffingtonpost.co.uk/news/jeremy-hunt" style="list-style-type: none; color: #058b7b; outline-width: 0px; padding-bottom: 0px; padding-top: 0px; outline-style: none; padding-left: 0px; text-decoration: none; margin: 0px; outline-color: invert; padding-right: 0px;border: 0px;" target="_hplink">&nbsp;Jeremy Hunt</a>&nbsp;will say today, as he calls on the health service to tackle the "silent scandal of errors".</p>
<p style="list-style-type: none; font-size: 15px; font-family: Georgia, Century, Times, serif; color: #333333; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 15px; line-height: 21px; padding-right: 0px;border: 0px;">The health service also recorded 326 "never events" - incidents so unacceptable that they should never happen in the last 12 months.</p>
<p style="list-style-type: none; font-size: 15px; font-family: Georgia, Century, Times, serif; color: #333333; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px 0px 15px; line-height: 21px; padding-right: 0px;border: 0px;">The figures come amid revelations that the Care Quality Commission&nbsp;<a href="http://www.huffingtonpost.co.uk/2013/06/21/cqc-cover-up-jill-finney_n_3476518.html?utm_hp_ref=uk" style="list-style-type: none; color: #058b7b; outline-width: 0px; padding-bottom: 0px; padding-top: 0px; outline-style: none; padding-left: 0px; text-decoration: none; margin: 0px; outline-color: invert; padding-right: 0px;border: 0px;" target="_hplink">covered up a spate of mother and baby deaths</a>&nbsp;at Morecambe Bay Trust, and days after it was&nbsp;shown the NHS had paid up to&nbsp;<a href="http://www.huffingtonpost.co.uk/2013/06/12/nhs-gagging-orders_n_3426090.html" style="list-style-type: none; color: #058b7b; outline-width: 0px; padding-bottom: 0px; padding-top: 0px; outline-style: none; padding-left: 0px; text-decoration: none; margin: 0px; outline-color: invert; padding-right: 0px;border: 0px;" target="_hplink">&pound;2million to stop potential NHS whistleblowers</a>from speaking out.</p>
这是保存在 xml 中的 htmlencoded 文本
谁能让我知道做错了什么,或者我需要做些什么来解决这个问题。我尝试了很多方法,但还没有运气。
任何帮助表示赞赏。