简体   繁体   中英

Javascript html decoding

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!

这里有很好的功能,可以帮到你 - 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,'>');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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