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


jQuery callbacks.locked()用法及代码示例


jQuery中的callbacks.locked()方法用于回答回调列表是否已被锁定。

用法:

callbacks.locked()

返回值:此方法返回一个布尔值。

范例1:在此示例中,回调已被锁定,因此该方法返回true。

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 | callbacks.remove() method 
    </p> 
  
    <button onclick="Geeks();"> 
        click here 
    </button> 
      
    <p id="GFG"></p> 
  
    <script> 
        var el_down = document 
                .getElementById("GFG"); 
  
        var res = ""; 
        var callbacks = jQuery.Callbacks(); 
  
        function Geeks() { 
            var func = function (val) { 
                res = res +  
                "value passed is - " + val; 
            }; 
  
            // Function added to list 
            callbacks.add(func); 
            callbacks.fire("gfg_1"); 
  
            // Locking the callback list 
            callbacks.lock(); 
              
            // Checking using this method 
            el_down.innerHTML = callbacks.locked(); 
        }  
    </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 | callbacks.remove() method 
    </p> 
  
    <button onclick="Geeks();"> 
        click here 
    </button> 
      
    <button onclick="lock();"> 
        lock here 
    </button> 
      
    <p id="GFG"></p> 
  
    <script> 
        var el_down = document.getElementById("GFG"); 
        var res = ""; 
        var callbacks = jQuery.Callbacks(); 
  
        // Defining lock function  
        function lock() { 
            callbacks.lock(); 
        } 
        function Geeks() { 
  
            // Function to be added to the list 
            var fun = function (val) { 
                res = res + "This is function " 
                    + "and value passed is "  
                    + val + "<br>"; 
            }; 
              
            // Adding 
            callbacks.add(fun); 
            callbacks.fire("GFG_1"); 
            el_down.innerHTML = callbacks.locked(); 
        }  
    </script> 
</body> 
  
</html>

输出:




相关用法


注:本文由纯净天空筛选整理自PranchalKatiyar大神的英文原创作品 JQuery callbacks.locked() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。