Chrome不允许使用制表符prevendefault [英] Chrome not allowing tab prevendefault

查看:104
本文介绍了Chrome不允许使用制表符prevendefault的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,用户可以在该表单上切换并跳到不同的元素.当它到达特殊的锚标签时,我将停止该标签.

I have a form on which user can tab and jump to different elements. i was to stop the tab when it reaches a special anchor tag.

这是在Firefox中工作的代码

this is the code which work in firefox

    $('.next-tab').keypress(function(e){
        var code = (e.keyCode ? e.keyCode : e.which);
        console.log(code);
        if (code == 0 || code == 9){
            console.log("keypress")
            e.preventDefault();
            e.stopPropagation();
        }
    });

但是此代码在chrome中不起作用,我不知道为什么,它甚至没有输入keypress方法. 所以我将此代码用于chrome

but this code does not work in chrome, i dont know why, it does not even enter the keypress method. so i used this code for chrome

$('.next-tab').blur(function(e) {
            var code = (e.keyCode ? e.keyCode : e.which);
            console.log(code);
            if (code == 0 || code == 9){
                console.log("blur")
                e.preventDefault();
                e.stopPropagation();
            }
        });

通过条件进入模糊方法,但不执行任何操作,用户可以轻松移至下一个元素.

it enters the blur method pass the condition but dont do any thing, and user can easily move to the next element.

推荐答案

要获得chrome支持,您似乎需要使用keydown事件:

For chrome support, looks like you need to use keydown event:

http://jsfiddle.net/qD2rk/

$('.next-tab').keydown(function (e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    console.log(code);
    if (code == 0 || code == 9) {
        console.log("keydown")
        e.preventDefault();
        e.stopPropagation();
    }
});

这篇关于Chrome不允许使用制表符prevendefault的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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