Home  >  Article  >  Web Front-end  >  ie和firefox不兼容的解决方法集合_javascript技巧

ie和firefox不兼容的解决方法集合_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:53:39957browse
1、firefox和ie事件event处理
在ie中,事件对象是作为一个全局变量来保存和维护的。 所有的浏览器事件,不管是用户触发
的,还是其他事件, 都会更新window.event 对象。 所以在代码中,只要轻松调用 window.event
就可以轻松获取 事件对象, 再 event.srcElement 就可以取得触发事件的元素进行进一步处理
在ff中, 事件对象却不是全局对象,一般情况下,是现场发生,现场使用,ff把事件对象自动传
递给对应的事件处理函数。 在代码中,函数的第一个参数就是ff下的事件对象了。

<script> <BR>function foo4(){ <BR>var evt=getEvent(); <BR>var element=evt.srcElement || evt.target ; <BR>alert(element.id) <BR>} <BR>function getEvent() <BR>{ //同时兼容ie和ff的写法 <BR>if(document.all) return window.event; <BR>func=getEvent.caller; <BR>while(func!=null){ <BR>var arg0=func.arguments[0]; <BR>if(arg0){ <BR>if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){ <BR>return arg0; <BR>} <BR>} <BR>func=func.caller; <BR>} <BR>return null; <BR>} <BR></script>
2、firefox和ie对手型指针cursor不兼容
手型指针有cursor:hand和cursor:pointer两种写法,其中cursor:hand在ff中不支持,返回错误!
只要使用cursor:pointer即可,ff和ie都支持!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn