首頁  >  文章  >  web前端  >  當滑鼠指標在HTML元素上移動時,執行一個腳本?

當滑鼠指標在HTML元素上移動時,執行一個腳本?

PHPz
PHPz轉載
2023-08-30 09:29:171343瀏覽

當滑鼠指標在HTML元素上移動時,執行一個腳本?

在HTML中,onmouseover #屬性在滑鼠指標移到元素上時觸發。

範例

您可以嘗試執行下列程式碼來實作onmouseover 屬性−

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onmouseover = "display()">
         This is demo heading.
      </h3>
      <p>Keep the mouse cursor on the heading to change the color.</p>
      <script>
         function display() {
            document.getElementById("myid").style.color = "red";
         }
      </script>
   </body>
</html>

以上是當滑鼠指標在HTML元素上移動時,執行一個腳本?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除