當滑鼠指標懸停在 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>

更新時間: 2020 年 5 月 30 日

284 次瀏覽

啟動你的 職業生涯

透過完成該課程獲得認證

開始
廣告
© . All rights reserved.