Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> HTML

เรียกใช้สคริปต์เมื่อกดปุ่มเมาส์ลงบนองค์ประกอบใน HTML หรือไม่


ใช้ onmousedown แอตทริบิวต์ใน HTML เพื่อรันสคริปต์เมื่อกดปุ่มเมาส์ลงบนองค์ประกอบ

ตัวอย่าง

คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อใช้งาน onmousedown แอตทริบิวต์ −

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onmousedown = "mouseDown()" onmouseup = "mouseUp()">
         This is demo heading.
      </h3>
      <p>Click above and then release.</p>
      <script>
         function mouseDown() {
            document.getElementById("myid").style.color = "yellow";
         }
         function mouseUp() {
            document.getElementById("myid").style.color = "blue";
         }
      </script>
   </body>
</html>