JavaScript 中 oninput 事件的用法是什麼?


如果在輸入框中新增一個值,那麼 oninput 事件就會發生。你可以嘗試執行以下程式碼來了解如何在 JavaScript 中實現 oninput 事件 −

示例

<!DOCTYPE html>
<html>
   <body>
      <p>Write below:</p>
      <input type = "text" id = "newInput" oninput = "inputFunc()">
      <p id = "demo"></p>
      <script>
         function inputFunc() {
            var a = document.getElementById("newInput").value;
            document.write("Typed: " + a);
         }
      </script>
   </body>
</html>

更新於:2020 年 6 月 23 日

284 次瀏覽

開啟你的職業生涯

透過完成課程認證

開始
廣告
© . All rights reserved.