當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


jQuery deferred.done()用法及代碼示例

jQuery中的deferred.done()方法用於添加處理程序,這些處理程序在解析延遲的對象時將被調用。

用法:

deferred.done(Callbacks [, Callbacks])

參數:

  • Callbacks:此參數指定一個函數或函數數組,在解析Deferred時將調用它們。
  • Callbacks:此參數指定可選的附加函數或函數數組,在解析Deferred時會調用它們。

返回值:此方法返回延遲的對象。

範例1:



html

<!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 succeessfully completed!"); 
            }); 
        }  
    </script> 
</body> 
  
</html>


輸出:
  • 在點擊按鈕之前:

  • 單擊按鈕後:

範例2:

html

<!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 succeessfully completed"; 
            }); 
        }  
    </script> 
</body> 
  
</html>

輸出:




相關用法


注:本文由純淨天空篩選整理自PranchalKatiyar大神的英文原創作品 jQuery deferred.done() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。