`
gupaohao
  • 浏览: 23436 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
最近访客 更多访客>>
社区版块
存档分类
最新评论

Firefox浏览器兼容JS脚本供参考

 
阅读更多

                   
                                                                最近做了一个项目,遇到了
[url=http://www.knowsky.com/article.asp?typeid=151]
FireFox
[/url]
和IE脚本不兼容的问题,为此从网上搜集了部分兼容的脚本,另外自己也摸索了一点,原本写在了自己另外一个博客里,现拷过来供大家参考,原文
[url=http://onlyaa.com/html/jsjc/20080515/2078.html#1]
1.window.event兼容脚本
[/url]

[url=http://onlyaa.com/html/jsjc/20080515/2078.html#2]
2.屏蔽Form提交事件
[/url]

[url=http://onlyaa.com/html/jsjc/20080515/2078.html#3]
3.获取事件源
[/url]

[url=http://onlyaa.com/html/jsjc/20080515/2078.html#4]
4.添加事件兼容写法
[/url]

[url=http://onlyaa.com/html/jsjc/20080515/2078.html#5]
5.Firefox注册innerText写法
[/url]

[url=http://onlyaa.com/html/jsjc/20080515/2078.html#6]
6.长度
[/url]

[url=http://onlyaa.com/html/jsjc/20080515/2078.html#7]
7.父控件下的子控件
[/url]

[url=http://onlyaa.com/html/jsjc/20080515/2078.html#8]
8.
Xml
Http
[/url]

1.window.event兼容脚本
function getEvent(){ //获取浏览器事件,同时兼容ie和ff的写法
if(document.all) return window.event;
func=getEvent.caller;
while(func!=null){
var arg0=func.arguments[0];
if(arg0){
if((arg0.constructor==Event    arg0.constructor ==MouseEvent)
   (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){
return arg0;
}
}
func=func.caller;
}
return null;
}
每次用事件之前Firefox都需要用getEvent()获取一下,否则就是空
2.屏蔽Form提交事件
event.returnValue=false;// for IE
evt.preventDefault();//for firefox
3.获取事件源
var source=event.srcElement //IE
var source=event.target //firefox
4.添加事件兼容写法
function addEvent(oElement,sEvent,func){
if (oElement.attachEvent){
oElement.attachEvent(sEvent,func);
}
else{
sEvent=sEvent.substring(2,sEvent.length);
oElement.addEventListener(sEvent,func,false);
}
}
用法:addEvent(window,"onload",Start);
5.Firefox注册innerText写法
  //注册firefox innerText
HTMLElement.prototype.__defineGetter__("innerText",
function(){
var anyString = "";
var childS = this.childNodes;
for(var i=0; i if(childS[1i].nodeType==1)
anyString += childS[1i].tagName=="BR" ? '\n' : childS[1i].innerText;
else if(childS[1i].nodeType==3)
anyString += childS[1i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__("innerText",
function(sText){
this.textContent=sText;
}
); [/1i][/1i][/1i][/1i][/1i]
6.长度:FireFox长度必须加“px”,IE无所谓

7.父控件下的子控件:IE是“children”,FireFox是“childNodes”

8.XmlHttp

在IE中,XmlHttp.send(content)方法的content可以为空,而firefox则不能为空,应该用send(" "),否则会出现411错误
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics