function htmlEncode(html){
return document.createElement('a').appendChild(document.createTextNode(html));
}
console.log(htmlEncode("<p>"))
输出结果 "<p>"
function htmlEncode(html){
return document.createElement('a').appendChild(document.createTextNode(html).parentNode.innerHTML);
}
console.log(htmlEncode("<p>"))
为何输出的结果变成了
<p>
它的innerHTML明明是 <p>
?