html 转义反转义-2017-12-26 14:59:06

function HTMLEncode(html) {
    var temp = document.createElement("div");
    (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
    var output = temp.innerHTML;
    temp = null;
    return output;
}


function HTMLDecode(text) { 
    var temp = document.createElement("div"); 
    temp.innerHTML = text; 
    var output = temp.innerText || temp.textContent; 
    temp = null; 
    return output; 

}


文章来源:https://www.cnblogs.com/zzgblog/p/5819807.html

使用场景: 用于服务器端返回的 html.tostring()  需要添加到html页面

猜你喜欢

转载自blog.csdn.net/fy809178958/article/details/78902323