javascript firefox兼容ie的dom方法脚本_javascript技巧
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
c.push(cs[i]);}
return c;});
__defineGetter__("canHaveChildren",function(){
return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/i.test(this.tagName);});
__defineSetter__("outerHTML",function(s){
var r=this.ownerDocument.createRange();
r.setStartBefore(this);
void this.parentNode.replaceChild(r.createContextualFragment(s),this);
return s;});
__defineGetter__("outerHTML",function(){
var as=this.attributes;
var str=" for(var i=0,al=as.length;i
str+=" "+as[i].name+"=""+as[i].value+""";}
return this.canHaveChildren?str+">":str+">"+this.innerHTML+""+this.tagName+">";});
__defineSetter__("innerText",function(s){
return this.innerHTML=document.createTextNode(s);});
__defineGetter__("innerText",function(){
var r=this.ownerDocument.createRange();
r.selectNodeContents(this);
return r.toString();});
__defineSetter__("outerText",function(s){
void this.parentNode.replaceChild(document.createTextNode(s),this);
return s});
__defineGetter__("outerText",function(){
var r=this.ownerDocument.createRange();
r.selectNodeContents(this);
return r.toString();});
insertAdjacentElement=function(s,o){
return (s=="beforeBegin"&&this.parentNode.insertBefore(o,this))||(s=="afterBegin"&&this.insertBefore(o,this.firstChild))||(s=="beforeEnd"&&this.appendChild(o))||(s=="afterEnd"&&((this.nextSibling)&&this.parentNode.insertBefore(o,this.nextSibling)||this.parentNode.appendChild(o)))||null;}
insertAdjacentHTML=function(s,h){
var r=this.ownerDocument.createRange();
r.setStartBefore(this);
this.insertAdjacentElement(s,r.createContextualFragment(h));}
insertAdjacentText=function(s,t){
this.insertAdjacentElement(s,document.createTextNode(t));}
}
//XMLDOM兼容
window.ActiveXObject=function(s){
switch(s){
case "XMLDom":
document.implementation.createDocument.call(this,"text/xml","", null);
//domDoc = document.implementation.createDocument("text/xml","", null);
break;
}
}
XMLDocument.prototype.LoadXML=function(s){
for(var i=0,cs=this.childNodes,cl=childNodes.length;i
this.appendChild(this.importNode((new DOMParser()).parseFromString(s,"text/xml").documentElement,true));}
XMLDocument.prototype.selectSingleNode=Element.prototype.selectSingleNode=function(s){
return this.selectNodes(s)[0];}
XMLDocument.prototype.selectNodes=Element.prototype.selectNodes=function(s){
var rt=[];
for(var i=0,rs=this.evaluate(s,this,this.createNSResolver(this.ownerDocument==null?this.documentElement:this.ownerDocument.documentElement),XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),sl=rs.snapshotLength;i
return rt;}
XMLDocument.prototype.__proto__.__defineGetter__("xml",function(){
try{
return new XMLSerializer().serializeToString(this);}
catch(e){
return document.createElement("div").appendChild(this.cloneNode(true)).innerHTML;}});
Element.prototype.__proto__.__defineGetter__("xml",function(){
try{
return new XMLSerializer().serializeToString(this);}
catch(e){
return document.createElement("div").appendChild(this.cloneNode(true)).innerHTML;}});
XMLDocument.prototype.__proto__.__defineGetter__("text",function(){
return this.firstChild.textContent;});
Element.prototype.__proto__.__defineGetter__("text",function(){
return this.textContent;});
Element.prototype.__proto__.__defineSetter__("text",function(s){
return this.textContent=s;});
}

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

剪映是一款视频编辑工具,带有全面的剪辑功能,支持变速,有多样滤镜和美颜的效果,还有丰富的曲库资源。在这款软件中,可以直接对视频进行剪辑,也可以创建剪辑脚本,但是应该怎么操作呢?本篇教程小编就来介绍一下剪映制作脚本的方法。 制作方法 1、在电脑中点击打开剪映软件,然后找到“创作脚本”选项,点击打开。 2、在创作脚本页面中,输入“脚本标题”,然后在大纲中输入拍摄内容的简介。 3、如何在大纲中就能看到“分镜描述”选项,在框内可以

如何在Linux系统中执行.sh文件?在Linux系统中,.sh文件是一种被称为Shell脚本的文件,用于执行一系列的命令。执行.sh文件是非常常见的操作,本文将介绍如何在Linux系统中执行.sh文件,并提供具体的代码示例。方法一:使用绝对路径执行.sh文件要在Linux系统中执行一个.sh文件,可以使用绝对路径来指定该文件的位置。以下是具体的步骤:打开终

如何使用WebSocket和JavaScript实现在线语音识别系统引言:随着科技的不断发展,语音识别技术已经成为了人工智能领域的重要组成部分。而基于WebSocket和JavaScript实现的在线语音识别系统,具备了低延迟、实时性和跨平台的特点,成为了一种被广泛应用的解决方案。本文将介绍如何使用WebSocket和JavaScript来实现在线语音识别系

要在UbuntuLinux中删除FirefoxSnap,可以按照以下步骤进行操作:打开终端并以管理员身份登录到Ubuntu系统。运行以下命令以卸载FirefoxSnap:sudosnapremovefirefox系统将提示你输入管理员密码。输入密码并按下Enter键以确认。等待命令执行完成。一旦完成,FirefoxSnap将被完全删除。请注意,这将删除通过Snap包管理器安装的Firefox版本。如果你通过其他方式(如APT包管理器)安装了另一个版本的Firefox,则不会受到影响。通过以上步骤

我们为初学者设计了这份WindowsPowerShell脚本教程,无论您是技术爱好者还是希望提高脚本编写技能的专业人士。如果你对PowerShell脚本没有先验知识,这篇文章将从基础开始,为您量身定制。我们将帮助您掌握PowerShell环境的安装步骤,并逐步介绍PowerShell脚本的主要概念和功能。如果您已经做好准备,准备深入学习PowerShell脚本编程,那么让我们一起踏上这激动人心的学习之旅吧!什么是WindowsPowerShell?PowerShell是由微软开发的一个混合了命令

WebSocket与JavaScript:实现实时监控系统的关键技术引言:随着互联网技术的快速发展,实时监控系统在各个领域中得到了广泛的应用。而实现实时监控的关键技术之一就是WebSocket与JavaScript的结合使用。本文将介绍WebSocket与JavaScript在实时监控系统中的应用,并给出代码示例,详细解释其实现原理。一、WebSocket技

如何使用WebSocket和JavaScript实现在线预约系统在当今数字化的时代,越来越多的业务和服务都需要提供在线预约功能。而实现一个高效、实时的在线预约系统是至关重要的。本文将介绍如何使用WebSocket和JavaScript来实现一个在线预约系统,并提供具体的代码示例。一、什么是WebSocketWebSocket是一种在单个TCP连接上进行全双工

如何利用JavaScript和WebSocket实现实时在线点餐系统介绍:随着互联网的普及和技术的进步,越来越多的餐厅开始提供在线点餐服务。为了实现实时在线点餐系统,我们可以利用JavaScript和WebSocket技术。WebSocket是一种基于TCP协议的全双工通信协议,可以实现客户端与服务器的实时双向通信。在实时在线点餐系统中,当用户选择菜品并下单
