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


JQuery mouseleave()用法及代码示例


mouseleave()方法是jQuery中的内置方法,当鼠标指针离开所选元素时可以使用。

用法:

$(selector).mouseleave(function)

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


返回值:此方法返回所选元素,并通过mouseleave()方法进行更改。

下面的示例说明了jQuery中的mouseleave()方法:

例:

<!DOCTYPE html> 
<html> 
    <head> 
        <title>The mouseleave 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() { 
                $("p").mouseleave(function() { 
                    $("p").css("background-color", "lightgreen"); 
                }); 
            }); 
        </script> 
        <style> 
            body { 
                width: 300px; 
                padding: 40px; 
                height: 30px; 
                border: 2px solid green; 
                font-weight: bold; 
                font-size: 20px; 
            } 
        </style> 
    </head> 
       
    <body> 
        <!-- move over this paragraph and see the change -->
        <p>Welcome to GeeksforGeeks!</p> 
    </body> 
</html>

输出:
在将鼠标移到段落上之前:

将鼠标移到该段之后。

相关文章:



相关用法


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