jQuery focusout()方法

jQuery focusout()方法

jQuery focusout()是一个内置的方法,用于移除所选元素的焦点。

语法:

$(selector).focusout(function);

参数:它接受一个参数 “函数”,它将在执行淡出方法后被执行。

例子1: jQuery代码显示了focusout()方法的工作原理。

<!DOCTYPE html>
<html>
  
<head>
    <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").focusin(function () {
                (this).css("background-color", "green");
            });
            ("div").focusout(function () {
                $(this).css("background-color", "#FFFFFF");
            });
        });
    </script>
    <style>
        div {
            border: 2px solid black;
            width: 50%;
            padding: 20px;
        }
  
        input {
            padding: 5px;
            margin: 10px;
        }
    </style>
</head>
  
<body>
    <!-- click inside the field focusin will take place and when
                    click outside focusout will take place -->
    <div>
        Enter name:
        <input type="text">
        <br>
    </div>
</body>
  
</html>

输出:

jQuery focusout()方法

实例2:在这个例子中,我们将通过使用focusin()和focusout()对输入框进行动画处理。

<!DOCTYPE html>
<html>
  
<head>
    <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").focusin(function () {
                ("input").animate({ fontSize: "+=14px"});
            });
            ("div").focusout(function () {
                $("input").animate({ fontSize: "-=14px"});
            });
        });
    </script>
    <style>
        div {
            border: 2px solid green;
            width: 50%;
            padding: 20px;
        }
  
        input {
            padding: 5px;
            margin: 10px;
        }
    </style>
</head>
  
<body>
    <!-- click inside the field focusin will take place and when
                    click outside focusout will take place -->
    <div>
        Enter name:
        <input type="text">
        <br>
    </div>
  
</body>
  
</html>

输出:

jQuery focusout()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程