在 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

287 次瀏覽

開始你的 職業

完成課程即可獲得認證

開始
廣告
© . All rights reserved.