覆盖FF,chrome中的F1键,即.ie8/chrome 上的 F1 是按键还是 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?

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

问题描述

我正在使用 jquery 创建命名空间事件.当我将以下函数与 code=112 一起使用时,函数 bool=false,在 FF 中一切正常,并且 F1 键提交给我的函数,并且事件不会冒泡以在新选项卡中打开 firefox 帮助.

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,chrome中的F1键,即.ie8/chrome 上的 F1 是按键还是 FF 按键?&lt;tab&gt; 怎么样?在输入字段中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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