Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Cách sử dụng sự kiện onfocusout trong JavaScript?

Sự kiện onfocusout kích hoạt khi phần tử sắp mất focus (tương tự onblur nhưng hỗ trợ bubbling).

Ví dụ

<!DOCTYPE html>
<html>
  <body>
    <p>Viết bên dưới:</p>
    <p>Sau khi mất focus, màu nền input sẽ đổi.</p>
    <input type="text" onfocusout="newFunc(this)">
    <script>
      function newFunc(x) {
        x.style.background = "blue";
      }
    </script>
  </body>
</html>