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 trên phần tử trong HTML?

Khi con trỏ chuột di chuyển trên một phần tử, thuộc tính onmousemove kích hoạt. Bạn có thể chạy mã sau để triển khai thuộc tính onmousemove:

Ví dụ

<!DOCTYPE html>
<html>
  <body>
    <h3 id="myid" onmousemove="mouseMove()">
      Đây là tiêu đề demo.
    </h3>
    <p>Nhấn vào trên rồi thả ra.</p>
    <script>
      function mouseMove() {
        document.getElementById("myid").style.color = "red";
      }
    </script>
  </body>
</html>