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


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

JQuery中的此deferred.notify()方法用於使用給定參數調用Deferred對象上的progressCallbacks。

用法:

deferred.notify(params)

參數:

  • params:這是可選參數,傳遞給progressCallbacks。

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

下麵討論了兩個示例:

  • 例:在此示例中,使用參數調用notify()。
    <!DOCTYPE HTML>  
    <html>   
    <head>  
        <title>  
          JQuery | deferred.notify() method 
        </title> 
        <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 id="GFG_UP">  
        </p> 
        <button onclick = "Geeks();"> 
        click here 
        </button> 
        <p id="GFG_DOWN">  
        </p> 
        <script>  
            var el_up = document.getElementById("GFG_UP"); 
            el_up.innerHTML = "JQuery | deferred.notify() method"; 
            function Func(val, div){ 
              $(div).append('From function "Func":' + val); 
            } 
            function Geeks() { 
                var def = $.Deferred(); 
                def.progress(Func); 
                def.notify( 
    'notify() is called with arguments. <br />', '#GFG_DOWN'); 
            }  
        </script>  
    </body>    
    </html>        
         
  • 輸出:
  • 例:在此示例中,不帶參數的情況下調用了notify()。

    <!DOCTYPE HTML>  
    <html>   
    <head>  
        <title>  
          JQuery | deferred.notify() method 
        </title> 
        <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 id="GFG_UP">  
        </p> 
        <button onclick = "Geeks();"> 
        click here 
        </button> 
        <p id="GFG_DOWN">  
        </p> 
        <script>  
            var el_up = document.getElementById("GFG_UP"); 
            el_up.innerHTML = "JQuery | deferred.notify() method"; 
            function Func(val, div){ 
              $(div).append('From function "Func":' + val); 
            } 
            function Geeks() { 
                var def = $.Deferred(); 
                def.done(Func); 
                def.progress(Func); 
                def.notify(); 
                def.resolve('Deferred is resolved.<br />', '#GFG_DOWN') 
            }  
        </script>  
    </body>    
    </html> 
  • 輸出:



相關用法


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