Javascript replacing HTML char code with actual character
问题 I have a HTML input text, and its values are populated from a related div. My problem is that the div contains characters like & which will display correcly as '&' sign in div but when copied to text box the text '&' will be dispalyed How can i convert & to & and '<' to '<' , ' ' to ' ' ??? 回答1: You thus want to unescape HTML entities. With plain JS you can use this snippet: function unescapeHTML(html) { var div = document.createElement("DIV"); div.innerHTML = html; return ("innerText" in div