當滑鼠指標移出 HTML 中的元素時執行某個指令碼?


當滑鼠指標移出某個元素時,onmouseout 屬性被觸發。你可以嘗試以下程式碼來實現 onmouseout 屬性 −

示例

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onmouseout = "mouseOut()">
         This is demo heading.
      </h3>
      <p>Click above and then release.</p>

      <script>
         function mouseOut() {
            document.getElementById("myid").style.color = "red";
         }

      </script>
   </body>
</html>

更新於: 03-Mar-2020

100 次瀏覽

開啟你的職業旅程

完成課程,獲取認證

開始
廣告
© . All rights reserved.