Unescape HTML entities in Javascript?

前端 未结 30 3566
野趣味
野趣味 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:58

    function decodeHTMLContent(htmlText) {
      var txt = document.createElement("span");
      txt.innerHTML = htmlText;
      return txt.innerText;
    }
    
    var result = decodeHTMLContent('One & two & three');
    console.log(result);

提交回复
热议问题