Unescape HTML entities in Javascript?

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

    First create a somewhere in the body

    Next, assign the string to be decoded as innerHTML to this:

    document.getElementById("decodeIt").innerHTML=stringtodecode
    

    Finally,

    stringtodecode=document.getElementById("decodeIt").innerText
    

    Here is the overall code:

    var stringtodecode="Hello world
    "; document.getElementById("decodeIt").innerHTML=stringtodecode; stringtodecode=document.getElementById("decodeIt").innerText

提交回复
热议问题