如何防止 html 实体 转义


 

var decodeHTML = function (html) {

    var txt = document.createElement('textarea');

    txt.innerHTML = html;

    return txt.value;

};

 

// Example

// Returns "

In this course, you'll learn:

"

var decoded = decodeHTML('<p>In this course, you’ll learn:</p>');

 

html转义方法:

function encodeHTMLEntities(text) {

var textArea = document.createElement('textarea');

textArea.innerText = text;

return textArea.innerHTML;

}

 

文章来源:刘俊涛的博客 欢迎关注公众号、留言、评论,一起学习。

__________________________________________________________________________________

若有帮助到您,欢迎点击推荐,您的支持是对我坚持最好的肯定(*^_^*)