Javascript String对象扩展HTML编码和解码的方法
更新时间:2009年06月02日 17:34:03 作者:
Javascript String对象扩展HTML编码和解码的代码
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud)
(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun)
复制代码 代码如下:
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;
}
相关文章
layer实现登录弹框,登录成功后关闭弹框并调用父窗口的例子
今天小编就为大家分享一篇layer实现登录弹框,登录成功后关闭弹框并调用父窗口的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2019-09-09textContent在Firefox下与innerText等效的属性
textContent在Firefox下与innerText等效的属性...2007-05-05
最新评论