手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >Javascript String对象扩展HTML编码和解码的方法
Javascript String对象扩展HTML编码和解码的方法
摘要:复制代码代码如下:String.prototype.HTMLEncode=function(){vartemp=document.creat...

复制代码 代码如下:

String.prototype.HTMLEncode = function() {

var temp = document.createElement ("div");

(temp.textContent != null) ? (temp.textContent = this) : (temp.innerText = this);

var output = temp.innerHTML;

temp = null;

return output;

}

String.prototype.HTMLDecode = function() {

var temp = document.createElement("div");

temp.innerHTML = this;

var output = temp.innerText || temp.textContent;

temp = null;

return output;

}

【Javascript String对象扩展HTML编码和解码的方法】相关文章:

javascript常用的方法分享

javascript使用Promise对象实现异步编程

JavaScript获取并更改input标签name属性的方法

JavaScript中的toUTCString()方法使用详解

JavaScript获取当前运行脚本文件所在目录的方法

javascript基于DOM实现省市级联下拉框的方法

JavaScript实现弹出模态窗体并接受传值的方法

javascript先序遍历DOM树的方法

JavaScript中length属性的使用方法

简述JavaScript中正则表达式的使用方法

精品推荐
分类导航