有没有办法禁用输入类型=“文本"上的“标签"? [英] is there a way to disable 'tab' on a input type='text'?

查看:133
本文介绍了有没有办法禁用输入类型=“文本"上的“标签"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有跨浏览器的解决方案来禁用输入type ='text'上的'tab'?

is there a cross-browser solution to disable 'tab' on a input type='text' ?

<input type='text' />

按下选项卡"将您移至下一个可聚焦"组件(例如按钮)

Pressing 'tab' moves you to the next 'focusable' component (for example a button)

我想改为使用"tab"做其他事情. 例如 即使在Google搜索标签中,该标签也仅用于自动完成建议的文本,而不是将您移至下一个可聚焦的组件...

I want instead 'tab' to do something else. For example Even in a google search tab is just used to autocomplete the suggested text instead of moving you to the next focusable component...

谢谢

推荐答案

document.querySelector('input').addEventListener('keydown', function (e) {
    if (e.which == 9) {
        e.preventDefault();
    }
});

这取决于您正在谈论的跨浏览器方式,因为以上内容仅支持IE9(和其他现代浏览器).

Depends on how cross-browser you are talking though, as the above only supports IE9 (and other modern browsers).

http://jsfiddle.net/ExplosionPIlls/YVUzz/

IE8-使用attachEvent代替addEventListenere.keyCode代替e.which,并且没有preventDefault,但是您可以使用return false.

IE8- use attachEvent instead of addEventListener and e.keyCode instead of e.which, and there is no preventDefault, but you can use return false.

这篇关于有没有办法禁用输入类型=“文本"上的“标签"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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