Computer >> Máy Tính >  >> Lập trình >> Javascript

Việc sử dụng sự kiện oninput trong JavaScript là gì?


Khi một giá trị được thêm vào hộp nhập, thì sự kiện đầu vào sẽ xảy ra. Bạn có thể thử chạy mã sau để tìm hiểu cách triển khai oninput sự kiện trong JavaScript -

Ví dụ

<!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>