在 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>

更新於: 30-5-2020

284 瀏覽量

開啟你的 職業

透過完成課程獲取認證

開始
廣告