簡體   English   中英

如何在按下回車鍵時啟動/停止選取框?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM