gpt4 book ai didi

javascript - 如何让 div 或 span 标签接收 Javascript 中的 keydown 事件

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

例如,

<div onkeydown='alert(3)' style="background:yellow;height:300px;width:300px;">
Click at me first. and press a key to see the event
</div>

这是一个jsfiddle example

最佳答案

您可以在其上指定tabindex。

例如,

<div onkeydown='alert(3)' tabindex="0" style="background:yellow;height:300px;width:300px;">
Click at me first. and press a key to see the event
</div>

关于javascript - 如何让 div 或 span 标签接收 Javascript 中的 keydown 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33907266/

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