[英]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("<h1><span style="color: #ff0000;"><strong><span style="text-decoration: underline;">added general commetns</span></strong></span></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.