当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


JQuery mouseup()用法及代码示例


mouseup()方法是jQuery中的内置方法,当在选定元素上释放鼠标左键时,该方法起作用。

用法:

$(selector).mouseup(parameter)

参数:该方法接受可选的单参数函数。此参数用于指定调用mouseup事件时要运行的函数。


返回值:调用函数时,此方法返回具有更改的所选元素。

以下示例说明了jQuery中的mouseup()方法:

范例1:此示例包含参数。

<!DOCTYPE html> 
<html> 
    <head> 
        <title>The mouseup Method</title> 
        <script src= 
        "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
        </script> 
          
        <!-- jQuery code to show the working of this method -->
        <script> 
            $(document).ready(function() { 
                $("button").mouseup(function() { 
                    $("div").after( 
                     "<p style='color:green;'>Mouse button released.</p>"); 
                }); 
            }); 
        </script> 
        <style> 
            body { 
                width: 200px; 
                padding: 20px; 
                min-height: 100px; 
                border: 2px solid green; 
            } 
        </style> 
    </head> 
    <body> 
        <!-- click on this button and release -->
        <button>Click Here!</button> 
          
    </body> 
</html>

输出:
在单击按钮之前:

单击按钮后:

程序2:本示例不包含参数。

<!DOCTYPE html> 
<html> 
    <head> 
        <title>The mouseup Method</title> 
        <script src= 
        "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
        </script> 
          
        <!-- jQuery code to show the working of this method -->
        <script> 
            $(document).ready(function() { 
                $("div").mouseover(function() { 
                    $("p").mouseup().slideToggle(); 
                }); 
            }); 
        </script> 
        <style> 
            body { 
                width: 340px; 
                padding: 20px; 
                height: 100px; 
                border: 2px solid green; 
                font-weight: bold; 
                font-size: 20px; 
            } 
        </style> 
    </head> 
    <body> 
       
        <p>Welcome to GeeksforGeeks!</p> 
          
        <!-- move over this text to see the change -->
        <div>Mouse over this text to see the change.</div> 
       
    </body> 
</html>

输出:
在将鼠标移到div元素上之前:

将鼠标移到div元素上之后:

相关文章:



相关用法


注:本文由纯净天空筛选整理自kundankumarjha大神的英文原创作品 jQuery | mouseup() with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。