javascript - HtmlEncode 方法和 HTMLDecode 方法


HTMLEncode() 方法

1 function HTMLEncode(html) {
2     var temp = document.createElement("div");
3     (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
4     var output = temp.innerHTML;
5     temp = null;
6     return output;
7 }

HTMLDecode() 方法

1 function HTMLDecode(text) {
2     var temp = document.createElement("div");
3     temp.innerHTML = text;
4     var output = temp.innerText || temp.textContent;
5     temp = null;
6     return output;
7 }

 

 


免责声明!

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



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