简体   繁体   English

Javascript html解码

[英]Javascript html decoding

When I receive html text by ajax in asp.net application it looks like: 当我在asp.net应用程序中通过ajax接收html文本时,它看起来像:

<span%20style='color:green;font-weight:bold'>%20Text%20Msg</span>

how is it possible in javascript decode that text to normal html? 怎么可能在javascript解码文本到正常的HTML?

<span style='color:green;font-weight:bold'> Text Msg </span>

Thanks! 谢谢!

这里有很好的功能,可以帮到你 - http://phpjs.org/functions/htmlspecialchars_decode:427

You are probably best suited with finding a server side solution as already mentioned in the comments, since this seems like a server side problem. 您可能最适合找到评论中已经提到的服务器端解决方案,因为这似乎是服务器端问题。

If you for some reason wish to do this client side anyway, here is a solution: 如果您出于某种原因希望无论如何都要做这个客户端,这里有一个解决方案:

var str = "&lt;span%20style='color:green;font-weight:bold'&gt;%20Text%20Msg&lt;/span&gt;";
var fixedStr = decodeURIComponent(str).replace(/&lt;/g,'<').replace(/&gt;/g,'>');

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM