當使用 HTML 中的元素按下滑鼠按鈕時執行指令碼?


在 HTML 中使用onmousedown屬性可以在元素按下的滑鼠按鈕執行指令碼。

示例

你可以試著執行以下程式碼,來實現onmousedown屬性 -

<!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-Mar-2020

285 個瀏覽量

開啟您的職業生涯

完成課程獲得認證

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