當滑鼠按鈕在 HTML 中某個元素上釋放時執行指令碼?


滑鼠按鈕在某個元素上釋放時,onmouseup 事件觸發。你可以嘗試執行以下程式碼來實現onmouseup 屬性 −

示例

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onmousedown = "mouseDown()" onmouseup = "mouseUp()">
         This is demo heading.
      </h3>
      <p>Click above and then release.</p>
      <script>
         function mouseDown() {
            document.getElementById("myid").style.color = "yellow";
         }
         function mouseUp() {
            document.getElementById("myid").style.color = "blue";
         }
      </script>
   </body>
</html>

更新時間: 03-3-2020

174 次瀏覽

開啟你的 職業

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.