gpt4 book ai didi

javascript - 隐藏元素时如何禁用 `accesskey`?

转载 作者:行者123 更新时间:2023-11-27 23:22:45 25 4
gpt4 key购买 nike

请看下面的代码:

$('div').click(function(){
alert("Shortcut worked although element was hidden!");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div hidden accesskey="1">
Some things...
</div>

<p>
Focus on me and then
</br>
<b>press [Alt + 1] please!</b>
</p>

当元素隐藏时,如何禁用 accesskey

最佳答案

我认为没有办法禁用accesskey,您只需要根据需要添加/删除

if(!$('div').is(":visible"))
{
$('div').removeAttr('accesskey');
}
else
{
$('div').attr('accesskey', '1');
}

if(!$('div').is(":visible"))
{
$('div').removeAttr('accesskey');
}
else
{
$('div').attr('accesskey', '1');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div hidden accesskey="1">
Some things...
</div>

<p>
Focus on me and then
</br>
<b>press [Alt + 1] please!</b>
</p>

关于javascript - 隐藏元素时如何禁用 `accesskey`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40232363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com