Unescape HTML entities in Javascript?

前端 未结 30 2977
野趣味
野趣味 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 06:03

    var encodedStr = 'hello & world';
    
    var parser = new DOMParser;
    var dom = parser.parseFromString(
        '' + encodedStr,
        'text/html');
    var decodedString = dom.body.textContent;
    
    console.log(decodedString);
    

提交回复
热议问题