只要滑鼠指標在 HTML 中元素上移動,就執行一個指令碼?


當滑鼠指標移到一個元素上時,onmousemove 屬性會被觸發。你可以嘗試以下程式碼來實現onmousemove 屬性 −

示例

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onmousemove = "mouseMove()">
         This is demo heading.
      </h3>
     <p>Click above and then release.</p>
     <script>
        function mouseMove() {
        document.getElementById("myid").style.color = "red";
        }
     </script>
   </body>
</html>

更新時間:2020 年 3 月 3 日

105 次瀏覽

Kickstart Your Career

透過完成課程獲得認證

開始
廣告
© . All rights reserved.