在网页上使用 TAB 按钮获取所选项目的标题

get title of items selected using TAB button, on a web page

我有一个没有图像的网络应用程序。它适用于视障人士。它是使用 TAB 按钮导航的。如何获取所选网页的 title/text,如按钮、菜单等。通过选择我的意思是使用 TAB 按钮,而不是鼠标点击。使用 Javascript 或任何其他语言。

使用jQuery库的.focusin()方法。尝试使用 TAB 按钮在下面代码段的表单输入上导航。

$(document).focusin(function(e) {
  console.log(e.target.name);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="#">
  <input type="text" name="input1"/>
  <input type="text" name="input2"/>
  <input type="text" name="input3"/>
</form>

我在示例中使用了事件目标的名称 属性,但您可以获得任何 属性 值。例如

$(document).focusin(function(e) {
  console.log($(e.target).attr("type"));
});

可以用同样的方法得到id和其他信息