html的转码玉反转码

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;   

}  

jQuery实现

 

function HTMLEncode(html)   

{   

return $(‘<div>‘).text(html).html()

 

}  

 function HTMLDecode(text)   

{   

return $(‘<div>‘).html(text).text()

}  

 

原文地址:https://www.cnblogs.com/blowfish/p/4689374.html