javascript; JS版HtmlEncode方法,结果与C#中HttpUtility.HtmlEncode方法一样。


<script type="text/javascript"> 
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; 
} 

var html = "<br>dffdfqqqqq"; 
var encodeHTML = HTMLEncode(html); 
alert("方法一:" +encodeHTML); 
var decodeHTML = HTMLDecode(encodeHTML); 
alert("方法一:" +decodeHTML); 
</script> 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM