IE浏览器兼容Firefox的JS脚本的代码
时间:2024-04-10 13:58:15
1.window.event兼容脚本
2.屏蔽Form提交事件
3.获取事件源
4.添加事件兼容写法
5.Firefox注册innerText写法
6.长度
7.父控件下的子控件
8.XmlHttp
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[i].nodeType==1)
anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__("innerText",
function(sText){
this.textContent=sText;
}
);
6.长度:FireFox长度必须加“px”,IE无所谓
7.父控件下的子控件:IE是“children”,FireFox是“childNodes”
8.XmlHttp
在IE中,XmlHttp.send(content)方法的content可以为空,而firefox则不能为空,应该用send(" "),否则会出现411错误
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python爬虫框架scrapy实现的文件下载功能示例
SQL查询不重复记录/删除重复记录
python实现输入数字的连续加减方法
用ASP实现在线压缩与解压缩
在Python的Flask框架中构建Web表单的教程
![](https://img.aspxhome.com/file/2023/5/90745_0s.png)
Python+eval函数实现动态地计算数学表达式详解
uni-app使用微信小程序云函数的步骤示例
![](https://img.aspxhome.com/file/2023/7/126497_0s.png)
Python 随机生成中文验证码的实例代码
python嵌套字典比较值与取值的实现示例
![](https://img.aspxhome.com/file/2023/5/103615_0s.png)
Pandas时间序列:时期(period)及其算术运算详解
PyTorch实现MNIST数据集手写数字识别详情
Python实战之自动发送邮件的实现
![](https://img.aspxhome.com/file/2023/0/90360_0s.png)
TensorFlow实现Softmax回归模型
浏览器是怎样工作的(一):基础知识
SQL学习笔记八 索引,表连接,子查询,ROW_NUMBER
运行(runCode)复制(copyCode)保存(saveCode)代码框方法
Python函数和模块的使用详情
python的列表List求均值和中位数实例
详解如何通过Mysql的二进制日志恢复数据库数据
![](https://img.aspxhome.com/file/2023/8/79998_0s.png)