让innerText在firefox火狐和IE浏览器都能用的写法
来源:互联网 发布:音乐制作软件手机版 编辑:程序博客网 时间:2024/05/18 07:06
IE中的获取文本方法innerText在firefox中不支持
firefox改成了textContent方法/属性
并且在Firefox中文本中间的空白自符被无情的替换没了
使用起来异常不方便
现在好了,用Javascript重新定义了innerText方法
使得在Firefox中也可以使用innerText方法
并且此方法解决了firefox中空白字符的问题
使用方法:
将下面的脚本放在页面内
不管ie还是firefox都可以使用obj.innerText提取文本了
复制代码 代码如下:
<script language=”javascript”>
function isIE(){ //ie?
if (window.navigator.userAgent.toLowerCase().indexOf(“msie”)>=1)
return true;
else
return false;
}
if(!isIE()){ //firefox innerText define
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].textContent;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__( “innerText”,
function(sText){
this.textContent=sText;
}
);
}
</script>
详细出处参考:http://www.jb51.net/article/27135.htm
- 让innerText在firefox火狐和IE浏览器都能用的写法
- 让IE和Firefox都支持innerText(textContent )
- 让IE和Firefox都支持innerText(textContent )
- firefox(火狐)与IE Chrome浏览器兼容的javascript和CSS写法
- innerText 兼容火狐 ie浏览器
- innerHTML与innerText在IE和Firefox下的区别。
- 火狐和IE都支持的浏览器关闭事件
- innerText兼容火狐和IE
- innerText兼容火狐和IE
- 如何让ActiveXObject( "Microsoft.XmlDom ")对象在非IE浏览器下显示数据?firefox(火狐)
- 如何让ActiveXObject( "Microsoft.XmlDom ")对象在非IE浏览器下显示数据?firefox(火狐)
- 7个javascript在IE和Firefox浏览器下的差异写法
- JavaScript在IE和Firefox(火狐)的不兼容问题解决
- 解决IE,火狐浏览器同时支持innerText
- IE和火狐的不兼容之innerText和textContent
- 火狐FF和IE兼容下innerText的问题处理
- 兼容Firefox(火狐)浏览器和IE浏览器的收藏代码
- 让IE、Firefox、Chrome中的LI都支持display-block的兼容写法
- 让你懂得职场的经典话语
- CentOS中vsftp安装与配置
- 性能测试工具LoadRunner知识点总结
- Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel,
- dd if 使用
- 让innerText在firefox火狐和IE浏览器都能用的写法
- 字体网站
- 图像几何变换:旋转,缩放,斜切
- C语言中scanf
- mysql 中 case 语句的运用
- 温故一
- iPhone5s照片被误删还能恢复吗
- 语音方案
- VC6.0 GDI+的配置过程