if(!document.all){ //zzcv的ff ie兼容脚本 /*脚本没有解决的问题及处理: 2.IE下,可以使用()或[]获取集合类对象;Firefox下,只能使用[]获取集合类对象. 解决方法:统一使用[]获取集合类对象. 3.IE下,可以使用获取常规属性的方法来获取自定义属性,也可以使用getAttribute()获取自定义属性;Firefox下,只能使用getAttribute()获取自定义属性. 解决方法:统一通过getAttribute()获取自定义属性. 4.IE下,html对象的ID可以作为document的下属对象变量名直接使用;Firefox下则不能. 5.Firefox下,可以使用与HTML对象ID相同的变量名;IE下则不能。 解决方法:使用document.getElementById("idName")代替document.idName.最好不要取HTML对象ID相同的变量名,以减少错误;在声明变量时,一律加上var,以避免歧义. 6.IE下input.type属性为只读;但是Firefox下input.type属性为读写. 8.IE下,可以通过showModalDialog和showModelessDialog打开模态和非模态窗口;Firefox下则不能 9.Firefox的body在body标签没有被浏览器完全读入之前就存在;而IE的body则必须在body标签被浏览器完全读入之后才存在 10. */ //文档兼容 HTMLDocument.prototype.__defineGetter__("all",function(){ return this.getElementsByName("*");}); HTMLFormElement.constructor.prototype.item=function(s){ return this.elements[s];}; HTMLCollection.prototype.item=function(s){ return this[s];}; //事件兼容 window.constructor.prototype.__defineGetter__("event",function(){ for(var o=arguments.callee.caller,e=null;o!=null;o=o.caller){ e=o.arguments[0]; if(e&&(e instanceof Event)) return e;} return null;}); window.constructor.prototype.attachEvent=HTMLDocument.prototype.attachEvent=HTMLElement.prototype.attachEvent=function(e,f){ this.addEventListener(e.replace(/^on/i,""),f,false);}; window.constructor.prototype.detachEvent=HTMLDocument.prototype.detachEvent=HTMLElement.prototype.detachEvent=function(e,f){ this.removeEventListener(e.replace(/^on/i,""),f,false);}; with(window.Event.constructor.prototype){ __defineGetter__("srcElement",function(){ return this.target;}); __defineSetter__("returnValue",function(b){ if(!b)this.preventDefault();}); __defineSetter__("cancelBubble",function(b){ if(b)this.stopPropagation();}); __defineGetter__("fromElement",function(){ var o=(this.type=="mouseover"&&this.relatedTarget)||(this.type=="mouseout"&&this.target)||null; if(o) while(o.nodeType!=1) o=o.parentNode; return o;}); __defineGetter__("toElement",function(){ var o=(this.type=="mouseover"&&this.target)||(this.type=="mouseout"&&this.relatedTarget)||null; if(o) while(o.nodeType!=1) o=o.parentNode; return o;}); __defineGetter__("x",function(){ return this.pageX;}); __defineGetter__("y",function(){ return this.pageY;}); __defineGetter__("offsetX",function(){ return this.layerX;}); __defineGetter__("offsetY",function(){ return this.layerY;}); } //节点操作兼容 with(window.Node.prototype){ replaceNode=function(o){ this.parentNode.replaceChild(o,this);} removeNode=function(b){ if(b) return this.parentNode.removeChild(this); var range=document.createRange(); range.selectNodeContents(this); return this.parentNode.replaceChild(range.extractContents(),this);} swapNode=function(o){ return this.parentNode.replaceChild(o.parentNode.replaceChild(this,o),this);} contains=function(o){ return o?((o==this)?true:arguments.callee(o.parentNode)):false;} } //HTML元素兼容 with(window.HTMLElement.prototype){ __defineGetter__("parentElement",function(){ return (this.parentNode==this.ownerDocument)?null:this.parentNode;}); __defineGetter__("children",function(){ var c=[]; for(var i=0,cs=this.childNodes;i
js firefox下兼容ie的dom的实现方法小结。利用我们为了兼容多浏览器写出更好的效果代码
Javascript 是一种由Netscape的LiveScript发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
来源: http://www.phperz.com/article/16/1208/288219.html