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


JQuery mouseout()用法及代码示例


jQuerymouseout()method 是一个内置方法,当鼠标指针移出所选元素时使用。

用法:

$(selector).mouseout(function)

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

示例 1:此示例说明了mouseout()方法的使用。

HTML


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

输出:

示例 2:在本例中,当鼠标移出段落时会弹出一个弹出窗口。

HTML


<!DOCTYPE html> 
<html> 
  
<head> 
    <title>The mouseover 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").mouseover(function () { 
                $("p").css("color", "red"); 
            }); 
            $("p").mouseout(function () { 
                alert("Mouse moved out from the paragraph"); 
            }); 
        }); 
    </script> 
    <style> 
        body { 
            width: 420px; 
            padding: 40px; 
            height: 30px; 
            border: 2px solid green; 
            font-weight: bold; 
            font-size: 20px; 
        } 
    </style> 
</head> 
  
<body> 
    <!-- move over this text to see the change -->
    <p>Move the mouse pointer over this paragraph.</p> 
</body> 
  
</html>

输出:



相关用法


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