IE、火狐(Firefox)和谷歌(Google Chrome)浏览器差异

来源:互联网 发布:mac zbrush 百度云 编辑:程序博客网 时间:2024/05/02 02:13

目前这个项目的页面要求javascript在IE、火狐(Firefox)和谷歌(Google Chrome)三个浏览器中都能运行,期间遇到一些问题,现总结一下:

1.获取鼠标的坐标时,使用event.clientX,不要使用event.x,因为火狐不支持event.x,最好使用event.screenX。

2.火狐中不能在js中直接使用event对象,必须将event传递给js方法再使用。例:
   <input name=”username” onclik=”alertMsg(event)”/>
   function alertMsg(eventObj)
   {
       alert(eventObj.clientX);
   }

3.火狐和谷歌在给obj.style.left和obj.style.top赋值时加上单位px,例:obj.style.left=100px。IE中可不加单位。

4.IE中增加事件用attachEvent,例:window.attachEvent(“onscroll”, functioname); 火狐和谷歌则用addEventListener,例:window.addEventListener(“scroll”,functioname, false);

5.火狐和IE中可以用document.documentElement.scrollTop获取滚动的高度,而在谷歌里要用document.body.scrollTop。

6.火狐和谷歌中不支持DIV的onresize事件

7.改变table的高度用table.style.height=”100px”,因为火狐和谷歌不支持table.height=”100px“这种写法。

8.动态添加文本时不要用innerText,用innerHTML,因为火狐用innerText在页面上看不到文本。

9.获取表单对象时用document.formname,不要直接写formname,因为在火狐上获取不到。

原创粉丝点击