Firfox中event is not defined问题?

可以运行:

window.addEventListener("DOMMouseScroll", function(event){
        var e=window.event||event||e;
        var a=e.detail;
        console.log(a);
    });

不可以运行:

 $(window).on("DOMMouseScroll",function(){
       var e=window.event||event||e;
        var a=e.detail;
        console.log(a);

    });

第一个用的就是源生js,下边用的就是jquery,为什么下边就会提示event is not defined呢??

阅读 4.6k
2 个回答

首先同意雨夹雪说的,DOMMouseScroll JQ不支持的。
其次是

$(window).on("DOMMouseScroll",function(){
       var e=window.event||event||e;
        var a=e.detail;
        console.log(a);

    });

这个event这个变量既不是形参,又不在上下文里,请问它不是not define是啥?你原生的实现把event形参删了照样报错。

jquery 对事件做了兼容处理,DOMMouseScroll只有firefox支持,jquery不支持

$(window).on("scroll",function(e){
 console.log(e);
});

这里是所有事件

推荐问题