简体   繁体   English

如何在服务器端编码的div中解码html?

[英]how to decode html in div encoded at server side?

I am using asp.net application. 我正在使用asp.net应用程序。 where I have generated JSON at server side in one of node of JSON has html formatted text so I have used httputility.htmlencode(); 我在JSON节点之一的服务器端生成JSON的地方使用了html格式的文本,因此我使用了httputility.htmlencode();。 so on client side I got it as 所以在客户端我得到了

<h1><span style="color: #ff0000;"><strong><span style="text-decoration: underline;">added general commetns</span></strong></span></h1>

and when I trying to render this in Div it is also rendering in above way. 当我尝试在Div中渲染它时,它也以上述方式渲染。 instead of that I want to see formatted text without <h1, it should be in way that with applied style. 与其说我不希望看到不带<h1的格式化文本,不如说是采用应用样式的方式。

how could it be possible? 怎么可能呢?

Duplicate question, but here is the answer from https://stackoverflow.com/a/1249234/5780021 重复的问题,但这是来自https://stackoverflow.com/a/1249234/5780021的答案

function htmlDecode(input){
  var e = document.createElement('div');
  e.innerHTML = input;
  return e.childNodes[0].nodeValue;
}

htmlDecode("&lt;h1&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&lt;strong&gt;&lt;span style=&quot;text-decoration: underline;&quot;&gt;added general commetns&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/h1&

Result is: 结果是:

<h1><span style="color: #ff0000;"><strong><span style="text-decoration: underline;">added general commetns</span></strong></span></h1>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将编码的json解码为HTML JS - How to decode encoded json to HTML JS 编码的 JavaScript:如何解码? - Encoded JavaScript: How to decode? 如何解码这个编码的 Javascript? - How to decode this encoded Javascript? 如何防止使用jsRender进行客户端HTML编码来编码服务器中已编码的字符串 - How to prevent client side HTML encoding with jsRender from encoding already encoded string from server 如何根据来自服务器端的信息添加 HTML div 元素? - How to add HTML div elements based on information from server side? 如何使用encodeURIComponent()解码在JS中编码的HTML? - How do I decode HTML that was encoded in JS using encodeURIComponent()? 如何为JavaScript解码编码的字符串 - How to decode encoded string for javascript 如何解码用 JavaScriptStringEncoded 编码的字符串? - How to decode a string encoded with JavaScriptStringEncoded? 当我单击使用附加的服务器端html编码中的第一个div时如何隐藏和显示另一个div - How to hide and show another div when I click first div in server side html coding using append 如何正确解码使用Html.Raw(Json.Encode(Model))编码的JSON字符串? - How to properly decode a JSON string encoded using Html.Raw(Json.Encode(Model))?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM