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

Thực thi script khi con trỏ chuột di chuyển qua phần tử trong HTML?

Thuộc tính onmouseover kích hoạt khi con trỏ chuột di chuyển qua một phần tử trong HTML.

Ví dụ

Bạn có thể chạy mã sau để triển khai thuộc tính onmouseover:

<!DOCTYPE html>
<html>
  <body>
    <h3 id="myid" onmouseover="display()">
      Đây là tiêu đề demo.
    </h3>
    <p>Giữ con trỏ chuột trên tiêu đề để đổi màu.</p>
    <script>
      function display() {
        document.getElementById("myid").style.color = "red";
      }
    </script>
  </body>
</html>