简体   繁体   English

在 JavaScript 中使用 Tab 键聚焦时显示链接的文本

[英]display text of a link when focused using tab key in JavaScript

Code:代码:

 <a href="#about"> About <abbr title="The Little Taco Shop">About LTS</abbr></a>

Display the text "About LTS" when we click on tab key in keyboard.当我们点击键盘上的 tab 键时,显示文本“关于 LTS”。

When the tab is focused on the link, the description tag becomes active. When the tab is focused on the link, the description tag becomes active. The description disappears when the focus is removed.移开焦点时,说明会消失。

Did you want this?你想要这个吗?

 document.addEventListener("keydown", (event)=> { if (event.keyCode === 9) { document.getElementById("focusBtn").addEventListener('focus', (event) => { document.getElementById("alt").style.display = "inline-block"; }); document.getElementById("focusBtn").addEventListener('focusout', (event) => { document.getElementById("alt").style.display = "none"; }); } });
 #alt{ display:none; margin-left:10px; }
 <a href="#about" id="focusBtn" > About <abbr id="alt" title="The Little Taco Shop">About LTS</abbr></a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM