e.preventDefault();在Firefox中行为不起作用? [英] e.preventDefault(); behaviour not working in Firefox?

查看:336
本文介绍了e.preventDefault();在Firefox中行为不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个基本的功能来处理关键事件,一切都很好。但是,在Firefox 9.0.1中,似乎无法阻止显示书签的默认事件。

I have this basic function for handling the key event, everything works great. However, in Firefox 9.0.1 it seems I can't prevent the default event which is showing of bookmarks.

有没有解决方案可以防止FF中的默认行为?

Is there any solution to prevent the default behaviour in FF?

$(document).keydown(function(evt) {     
    if (evt.which == 66 && evt.ctrlKey) {                             
         if (evt.preventDefault) {
             evt.preventDefault();
         } else {
             evt.returnValue = false;
         }    
         alert("Ctrl+B pressed");
         return false;                      
    }
});


推荐答案

看起来像某种关于警报。尝试这样:

Seems like some sort of bug regarding alert. Try this:

$(document).keydown(function(evt) {     
    if (evt.which == 66 && evt.ctrlKey) {                             
         if (evt.preventDefault) {
             evt.preventDefault();
         } else {
             evt.returnValue = false;
         }    
         console.log("Ctrl+B pressed");
         return false;                      
    }
});

现在没有为我打开书签工具栏。我假设你实际上不想要 alert ?只要不包含警报就可以调用您的方法。

Doesn't open the Bookmarks Toolbar for me now. I assume you don't actually want to alert do you? I think you can just call your method as long as it doesn't contain an alert.

这篇关于e.preventDefault();在Firefox中行为不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆