如何使用箭头键在 html 表格中向下滚动?

发布于 2024-09-06 10:12:59 字数 193 浏览 6 评论 0原文

我正在开发一个网络应用程序并遇到以下问题。

我的页面中有两个表,当我在 table1 中选择一行时,table2 中的第一行被选中。我想使用箭头键向下滚动 table2 (无需单击 table2 的任何行)。但是当我使用箭头键时,滚动条不起作用。仅当我单击 table2 中的一行后它才起作用。

有没有任何 javascript 解决方案?

I'm developing a web application and encountered following problem.

there are two tables in my page and when i select a row in table1 , first row in table2 get selected.I want to scroll down the table2 using arrow keys(without click in any row of table2). But when I use arrow keys, scroll bar doesn't work. It work only after I click a row in table2.

Is there any javascript solution for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趁微风不噪 2024-09-13 10:12:59

您可能需要设置焦点:

tables2.tabIndex = 1; // allows focus   
table2.focus();

You may need to set the focus:

tables2.tabIndex = 1; // allows focus   
table2.focus();
单身狗的梦 2024-09-13 10:12:59

您可能会从 javascript 获得按键和滚动。 jQuery 的滚动解决方案:

$('html, body').animate({scrollTop: 300}, 500);

将滚动到从顶部 300px 500ms

You may get pressed keys and scroll from javascript. Scrolling solution for jQuery:

$('html, body').animate({scrollTop: 300}, 500);

will scroll to 300px from top by 500ms

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文