欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

随机显示个性签名的js代码(兼容ie,firefox)_其他特效

程序员文章站 2022-05-06 17:45:02
...
原网页中用的是innerText,脚本之家这里给替换成了innerHTML是为了简单的支持firefox,因为firefox不支持innerText,但已经有办法让firefox支持innerText了,兼容代码如下。
复制代码 代码如下:

//让Mozilla支持innerText
try{
HTMLElement.prototype.__defineGetter__
(
"innerText",
function ()
{
var anyString = "";

var childS = this.childNodes;
for(var i=0; i{
if(childS[i].nodeType==1)
anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
}
catch(e){}

以下使用innerHTML实现的代码,其它更多的地方,大家自行测试因时间关系,不多说了。

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]