我在母版页上使用了 anchor 标记。在 TAB 键期间,当焦点出现在特定的 anchor 标记上时,然后 ENTER 键按下,它重定向到特定的链接页面。 anchor 标签工作正常。但我想要的是 当它打开特定的链接页面并重新加载页面时,焦点应保留在该特定链接上。这样在下一个 TAB 键按下 导航/焦点移动到下一个 anchor 标记。但是当前发生的是,当我们按 ENTER 键时, anchor 标记链接打开并在 TAB 上 按键默认导航从 URL 开始。
<div title="Main" >
<a href="/Home.aspx" id="home">
<div class="link-title">
Home
</div>
</a>
</div>
<div title="Contact" >
<a href="/Contact.aspx" id="contact>
<div class="link-title">
Contact
</div>
</a>
</div>
CSS代码如下:
/* To set keyboard focus on Tab press*/
a:focus
{
outline: 1px dotted black;
}
最佳答案
如果我没听错,这是我的报价:
在每个页面的 body
元素(例如)中添加一个 data
属性并设置值,例如每个 anchor
标记的索引,或其他内容作为 key
,然后在 page_load
上使用 jquery
读取 data
属性并根据值设置焦点。
<body data-index='1'>
// rest of the html
JS:
var index = $('body').data('index');
$anchors.eq(index).focus(); // you need to find `anchor` tags first.
希望这对您有所帮助。
关于javascript - 重新设置对 anchor 标记的关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31421604/