JQuery callbacks.locked()方法

JQuery callbacks.locked()方法

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

语法:

callbacks.locked()

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

例子1:在这个例子中,回调已经被锁定,所以该方法返回真。

<!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>

输出:

JQuery callbacks.locked()方法

例子2:这个例子提供了一个按钮来锁定列表,然后调用该方法来查看结果。

<!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>

输出:

JQuery callbacks.locked()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程