當用戶鬆開 HTML 中的鍵時執行指令碼?


使用 onkeyup 屬性。onkeyup 屬性在使用者釋放鍵時觸發。

示例

你可嘗試執行以下程式碼,以便在釋放鍵時執行指令碼 -

<!DOCTYPE html>
<html>
   <body>
      <p>Press a key inside the textbox.</p>

      <input type = "text" onkeydown = "display()">

      <script>
         function display() {
            alert("You released a key!");
         }
      </script>
   </body>
</html>

更新於:2020年3月3日

102 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.