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


jQuery callbacks.disabled()用法及代碼示例


jQuery callbacks.disabled()方法用於檢查回調是否已禁用。此方法根據回調返回“true”或“false”。

用法:

callbacks.disabled()

返回值:此方法返回一個布爾值。

範例1:本示例禁用回調,然後調用callbacks.disabled()方法以查看結果。

<!DOCTYPE HTML> 
<html> 
  
<head> 
    <title> 
        jQuery callbacks.disabled() 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"); 
        var el_down = document.getElementById("GFG_DOWN"); 
        el_up.innerHTML =  
            "JQuery | callbacks.disabled() method"; 
  
        var result = ""; 
        var callbacks = jQuery.Callbacks(); 
  
        function Geeks() { 
          
            // First function to be added to the list 
            var fun1 = function (val) { 
                result = result + "This is function 1 and" 
                    + " value passed is " + val + "<br>"; 
            }; 
  
            callbacks.add(fun1); // Adding the function 1 
            callbacks.fire("GFG_1"); // Calling the function 1 
            callbacks.disable(); 
            el_down.innerHTML = callbacks.disabled(); 
        }  
    </script> 
</body> 
  
</html>

輸出:

範例2:本示例提供了一個按鈕來禁用回調並進行檢查。

<!DOCTYPE HTML> 
<html> 
  
<head> 
    <title> 
        jQuery callbacks.disabled() 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> 
      
    <button onclick="disable();"> 
        disable 
    </button> 
      
    <p id="GFG_DOWN"></p> 
      
    <script> 
        var el_up = document.getElementById("GFG_UP"); 
        var el_down = document.getElementById("GFG_DOWN"); 
        el_up.innerHTML =  
                "JQuery | callbacks.disabled() method"; 
        var result = ""; 
        var callbacks = jQuery.Callbacks(); 
        function disable() { 
            callbacks.disable(); 
        } 
        function Geeks() { 
  
            // First function to be added to the list 
            var fun1 = function (val) { 
                result = result + "This is function 1 and" 
                    + " value passed is " + val + "<br>"; 
            }; 
            callbacks.add(fun1); // Adding the function 1 
            callbacks.fire("GFG_1"); // Calling the function 1 
            el_down.innerHTML = callbacks.disabled(); 
        }  
    </script> 
</body> 
  
</html>

輸出:




相關用法


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