当前位置:Gxlcms > JavaScript > 随机显示个性签名的js代码(兼容ie,firefox)

随机显示个性签名的js代码(兼容ie,firefox)

时间:2021-07-01 10:21:17 帮助过:4人阅读

原网页中用的是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<childS.length; 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需刷新才能执行]

人气教程排行