jQuery mouseout()方法

jQuery mouseout()方法

jQuery mouseout()方法是一个内置的方法,当鼠标指针从选定的元素上移开时使用。

语法:

$(selector).mouseout(function)

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

例子1:这个例子说明了mouseout()方法的使用。

<!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>

输出:

jQuery mouseout()方法

例子2:在这个例子中,当鼠标从段落中移出时,会有一个弹出窗口。

<!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>

输出:

jQuery mouseout()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程