javascript - (Vanilla JS) 使用已知索引值触发表格单元格的点击

标签 javascript navigation keyboard click

我正在为表格进行键盘导航,当我运行以下代码时收到此错误:

var newActiveCell = table.rows[activeRowIndex].cells[activeColumnIndex];
newActiveCell.click();

错误:

TypeError: undefined is not an object (evaluating 'table.rows[activeRowIndex].cells')

如果我然后执行 activeCell = document.activeElement 它可以与 .focus() 一起使用,但我想知道是否有更好的方法来编码整个概念。

我没有包含变量声明和处理键盘输入的函数以节省帖子中的空间,但本质上我想做的是触发对我有索引值的单元格的单击。

最佳答案

这为我修复了未定义的错误,我之前定义的行和列索引,每当有按键时我都会根据需要递增它们。

var newActiveCell = table.rows[activeRowIndex].cells[activeColumnIndex].focus();
activeCell = document.activeElement;

console.log(activeCell);

关于javascript - (Vanilla JS) 使用已知索引值触发表格单元格的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35075808/

相关文章:

javascript - 似乎无法让 jQuery .on 启动

c# - 当使用 RegionManager.RequestNavigate 方法添加 View 时,是否有任何方法可以从 Prism 区域中删除 View (按名称)?

javascript - 如何点击外部关闭导航栏?

macos - 热衷于在 MAC OS X 中获取格式为 "en_US"的键盘布局语言和区域设置?

javascript - 防止对象缩放

javascript - Jquery/Javascript - 存储字符串的最后 4 个字母(跨浏览器)

javascript - Promise 在 Jest 测试中没有正确拒绝

wpf - WPF 不可编辑组合框中的选项卡导航问题

ios - ios8 键盘高度有所不同

ios - 在 UITextField 中输入内容后 UIView 消失?