jQuery deferred.done()方法
在jQuery的这个deferred.done()方法是用来添加处理程序,当延迟对象被解决时,将被调用。
语法:
deferred.done(Callbacks [, Callbacks])
参数:
- Callbacks。这个参数指定一个函数,或函数数组,当递延解决时被调用。
 - Callbacks。这个参数指定了一个可选的附加函数,或函数数组,当递延解决时被调用。
 
返回值:该方法返回递延对象。
示例 1:
<!DOCTYPE HTML>
<html>
 
<head>
    <script src=
"https://code.jquery.com/jquery-3.5.0.js">
    </script>
</head>
 
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
     
     
<p>
        JQuery | deferred.done() method
    </p>
 
 
    <button onclick="Geeks();">
        click here
    </button>
     
    <script>
        function Geeks() {
            .get("testingGFG.php").done(function () {
                alert(".get successfully completed!");
            });
        }
    </script>
</body>
 
</html>
输出:
在点击按钮之前:

点击按钮后:

示例 2:
<!DOCTYPE HTML>
<html>
 
<head>
    <script src=
"https://code.jquery.com/jquery-3.5.0.js">
    </script>
</head>
 
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
     
     
<p>
        JQuery | deferred.done() method
    </p>
 
 
    <button onclick="Geeks();">
        click here
    </button>
 
    <p id="GFG_DOWN"></p>
 
 
     
    <script>
        var el_down = document
                .getElementById("GFG_DOWN");
        function Geeks() {
            .get("testingGFG.php")
                    .done(function () {
                el_down.innerHTML =
                ".get successfully completed";
            });
        }
    </script>
</body>
 
</html>
输出:

极客教程