在 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 次瀏覽

開啟您的 職業生涯

完成課程後獲得認證

開始
廣告