Unescape HTML entities in Javascript?

前端 未结 30 2941
野趣味
野趣味 2020-11-21 05:40

I have some Javascript code that communicates with an XML-RPC backend. The XML-RPC returns strings of the form:


30条回答
  •  终归单人心
    2020-11-21 05:48

    jQuery will encode and decode for you. However, you need to use a textarea tag, not a div.

    var str1 = 'One & two & three';
    var str2 = "One & two & three";
      
    $(document).ready(function() {
       $("#encoded").text(htmlEncode(str1)); 
       $("#decoded").text(htmlDecode(str2));
    });
    
    function htmlDecode(value) {
      return $("