Javascript html decoding

。_饼干妹妹 提交于 2019-12-10 16:54:52

问题


When I receive html text by ajax in asp.net application it looks like:

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

how is it possible in javascript decode that text to normal html?

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

Thanks!


回答1:


Nice function here that does it for you - http://phpjs.org/functions/htmlspecialchars_decode:427




回答2:


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,'>');


来源:https://stackoverflow.com/questions/4692882/javascript-html-decoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!