gpt4 book ai didi

javascript - 使用选项卡切换按钮

转载 作者:行者123 更新时间:2023-11-30 13:17:41 25 4
gpt4 key购买 nike

很简单。我在网页中有两个按钮。他们坐得很近。目前我用鼠标点击其中一个然后做一些事情。我们可以只使用 TAB 等键盘吗?

谢谢。

最佳答案

使用 Tab 键按下按钮将完全破坏您网站的可访问性,并将有效地驱赶任何键盘用户离开您的网站,这是一种糟糕的做法。

无论如何,您可能希望使用 jquery 捕获 '*' 的事件:

$('*').keydown(function(event) {
if (event.keyCode == 9)
//stuff
})

尽管我强烈建议反对这样做;永远不要覆盖 tab 等键的功能,否则会造成巨大的可访问性问题。

[编辑]:将事件添加到 document 可能更有效:

If key presses anywhere need to be caught (for example, to implement global shortcut keys on a page), it is useful to attach this behavior to the document object. Because of event bubbling, all key presses will make their way up the DOM to the document object unless explicitly stopped.

Source

关于javascript - 使用选项卡切换按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11416490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com