更新时间:2022-12-04 21:12:50
创建div,将其设置为innerHTML
,然后阅读innerText
var d = document.createElement("div");
d.innerHTML = "<html xmlns="http://www.w3.org/1999/xhtml" >";
alert(d.innerText || d.text || d.textContent);
How do i unescape HTML Entities in JS?
When googling i literally saw answers with a huge switch and people rolling their own.
I'd like the string <html xmlns="http://www.w3.org/1999/xhtml" >
to become <html xmlns="http://www.w3.org/1999/xhtml" >
Create a div, set it's innerHTML
and then read innerText
var d = document.createElement("div");
d.innerHTML = "<html xmlns="http://www.w3.org/1999/xhtml" >";
alert(d.innerText || d.text || d.textContent);