jQuery mouseup() 示例


jQuery 中的 mouseup() 方法用於觸發 mouseup 事件。該事件在所選元素上釋放滑鼠左鍵時發生。

語法

語法如下−

$(selector).mousedown(func)

上述 func 是 mouseup 事件觸發時要執行的函式。

示例

現在讓我們看一個實現 jQuery mouseup() 方法的示例−

 現場演示

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("h2").mouseup(function(){
         $(this).after("<p>Mouse up (mouse button is released).</p>");
      });
      $("h2").mousedown(function(){
         $(this).after("<p>Mouse down (mouse button is pressed down).</p>");
      });
   });
</script>
</head>
<body>
<h2>Press Here</h2>
</body>
</html>

輸出

這將產生以下輸出−

按住並釋放滑鼠按鈕,將顯示以下內容−

示例

現在我們來看另一個示例−

 現場演示

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("h2").mouseup(function(){
         alert("Mouse left released");
      });
   });
</script>
</head>
<body>
<h2>Press Here</h2>
</body>
</html>

輸出

這將產生以下輸出−

按住並釋放滑鼠−

更新於: 2019 年 12 月 30 日

309 次瀏覽

開啟你的事業

完成課程獲得認證

開始
廣告
© . All rights reserved.