使用左右箭头设置焦点(HTML + JS)
是否有任何方法可以使左箭头的行为类似于选项卡按钮(将焦点设置为下一个可聚焦项目),而右箭头的行为类似于shift+tab(将焦点设置为上一个可聚焦项目)?
我已经走到这一步了:
$().keypress(function(e) {
if (e.keyCode == 37) {
alert('I want to do a shift-tab');
}
else if (e.keyCode == 39) {
alert('I want to do a tab');
}
});
但是谷歌并没有那么有帮助,所以我想我应该在谷歌上搜索更多内容的同时在这里发布一个快速帖子。
谢谢!
哦,而且它纯粹是针对 FF3.0 的,所以我不需要担心其他浏览器的麻烦。
Is there any to make the left arrow behave like the tab button (set focus to the next focusable item) and the right arrow behave like a shift+tab (set focus to the previous focusable item)?
I've gotten this far:
$().keypress(function(e) {
if (e.keyCode == 37) {
alert('I want to do a shift-tab');
}
else if (e.keyCode == 39) {
alert('I want to do a tab');
}
});
But google isn't being that helpful so I thought I'd put a quick post up here while I google some more.
Thanks!
Oh, and it's purely for FF3.0 so I don't need to worry about other browser nuisances.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止你所拥有的看起来不错。
您可以保留“可聚焦”项目的列表,然后迭代该列表并保留指向当前项目的指针:
但这只是一个粗略的轮廓。 在执行某些操作之前,您需要检查 idx,以确保不会越过可聚焦元素数组的开头或结尾。 当用户位于文本框内时,您还需要小心调用此方法。
What you have so far seems fine.
You could keep a list of 'focusable' items and just iterate through the list keeping a pointer to the current one:
This is just a rough outline though. You'd need to check the
idx
before doing something to make sure you don't slip past the beginning or end of the focusable elements array. You'll also need to be careful about calling this when the user is inside of a textbox.