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

Thực thi script khi nút chuột được thả ra trên một phần tử trong HTML?

Khi nút chuột được thả ra trên một phần tử, sự kiện onmouseup được kích hoạt. Bạn có thể chạy mã sau để triển khai thuộc tính onmouseup:

Ví dụ

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