例如,
<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/