如何让div或span标记在Javascript中接收keydown事件
比如说,如何让div或span标记在Javascript中接收keydown事件,javascript,html,Javascript,Html,比如说, <div onkeydown='alert(3)' style="background:yellow;height:300px;width:300px;"> Click at me first. and press a key to see the event </div> <div onkeydown='alert(3)' tabindex="0" style="background:yellow;height:300px;width:300px;"&
<div onkeydown='alert(3)' style="background:yellow;height:300px;width:300px;">
Click at me first. and press a key to see the event
</div>
<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>
先点击我。然后按一个键查看事件
这是一个您可以在上面指定选项卡索引 比如说,
<div onkeydown='alert(3)' style="background:yellow;height:300px;width:300px;">
Click at me first. and press a key to see the event
</div>
<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>
先点击我。然后按一个键查看事件
出于某种原因,最简单的JS不能在JSFIDLE上工作。看这里:
函数keyD(){
document.getElementById(“黄色”).style.backgroundColor=“蓝色”;
}
函数keyU(){
document.getElementById(“黄色”).style.backgroundColor=“绿色”;
}