[英]How to start/stop marquee on enter key press?
以下是選取框在鼠標點擊時停止並在鼠標點擊時開始的代碼片段。 我需要更改它以檢測從鍵盤按下回車鍵的事件。 這怎么可能? 謝謝
<marquee behavior="scroll" direction="left" onmousedown="this.stop();" onmouseup="this.start();">
Go on... click me (and hold the mouse down)!
</marquee>
<!DOCTYPE html>
<html>
<body>
<marquee id="marquee" behavior="scroll" direction="left"
onmousedown="this.stop();" onmouseup="this.start();">
Go on... click me (and hold the mouse down)!
</marquee>
<script>
if(document.readyState){
const marquee = document.getElementById('marquee');
document.body.addEventListener('keydown',function(event){
if(event.key == 'Enter'){
marquee.stop()
}
})
document.body.addEventListener('keyup',function(event){
if(event.key == 'Enter'){
marquee.start()
}
})
}
</script>
</body>
</html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.