覆盖FF中的F1键,chrome,ie。 F1上的ie8 / chrome上键盘和FF按键?关于< tab>在输入字段? [英] Overriding the F1 key in FF, chrome, ie. Is F1 on ie8/chrome on keyup and in FF on keypress? What about <tab> in an input field?

查看:163
本文介绍了覆盖FF中的F1键,chrome,ie。 F1上的ie8 / chrome上键盘和FF按键?关于< tab>在输入字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jquery创建命名空间事件。当我使用下面的代码= 112函数,一个函数,bool = false,一切工作正常在FF和F1键提交到我的功能,该事件不起泡在新标签中打开firefox帮助。 p>

I'm creating namespaced events with jquery. When I use the following function with code=112, a function, bool=false, everything works fine in FF and the F1 key submits to my function and the event does not bubble up to open the firefox help in a new tab.

function bindKeyFunc(code, func, bool){
    $(document).bind('keypress.' + code, function(e){
        var c = (e.keyCode ? e.keyCode : e.which);
        //console.log(c);
        if ( code == c) {
            //e.stopPropagation();
            //e.preventDefault();
            func();
            return bool;
        }
    });
}

在chrome和ie8我的事件监听器不会触发,即使我取消注释stopPropagation和preventDefault调用。

In chrome and ie8 my event listener does not fire and the regular help occurs instead, even if I uncomment the stopPropagation and preventDefault calls.

同样,当我尝试接管< tab> 键为我自己的目的,它工作在FF的辉煌,但我的事件不会触发chrome或ie8,并且选项卡的默认动作改为:

Similarly, when I try to take over the <tab> key for my own purposes, it works splendidly in FF but my event doesn't fire in chrome or ie8 and the default action for the tab fires instead:

    $('input#manual-total').bind('keypress.dep', function(e) {
        var code = (e.keyCode ? e.keyCode : e.which);
        if ( code==9 ){
            $('div#formset').show();
            $(next).focus()[0].select();
            return false;
        }
    });


推荐答案

在浏览器中映射特殊键是一个混乱。特别是, IE当然不会为功能键启用按键事件。 onkeydown / up可能在IE上工作,虽然。许多键由不同的浏览器以不同的方式处理不正确。我强烈怀疑有一种处理F1的跨浏览器方法。抱歉;我知道这不是你想要的答案,但我相信这是真的。

Good luck. Mapping of special keys in browsers is a mess. In particular, IE certainly does not fire keypress events for function keys at all. onkeydown/up may work on IE, though. Many keys are handled incorrectly, in different ways by different browsers. I strongly doubt there is a cross-browser method of handling F1. Sorry; I know that's not the answer you wanted, but I believe it's the truth.

阅读链接的文章,特别是关于当我发现我决定不通过进行进一步的标点符号实验冒险我的理智。和类似物。 :)

Do read the linked article, particularly the occasional warnings about "When I discovered that I decided not to risk my sanity by performing further punctuation character experiments." and the like. :)

这篇关于覆盖FF中的F1键,chrome,ie。 F1上的ie8 / chrome上键盘和FF按键?关于&lt; tab&gt;在输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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