当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。