JQuery中的callbacks.disable()方法用于禁止回调列表进一步执行任何其他操作。此方法返回其附加到的Callbacks对象(此语法):
callbacks.disable()
下面讨论了两个示例:
-
例:本示例在添加和触发函数后禁用回调。
<!DOCTYPE HTML> <html> <head> <title> JQuery | callbacks.disable() 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.disable() method"; var res = ""; function Geeks() { // first function to be added to the list var fun1 = function(val) { res = res + "This is function 1 and value passed is " + val + "<br>"; }; // second function to be added to the list var fun2 = function(val) { res = res + "This is function 2 and value passed is" + val + "<br>"; }; var callbacks = jQuery.Callbacks(); callbacks.add(fun1); // adding the function 1 callbacks.fire("GFG_1"); // calling the function 1 callbacks.disable(); /*disables further calls to a callback list*/ callbacks.add(fun2); // This will not work. callbacks.fire("GFG_2"); // This will not work. el_down.innerHTML = res; } </script> </body> </html>
-
输出:
-
例:此示例提供了一个按钮,该按钮首先禁用回调,然后添加并触发该方法以查看结果。
<!DOCTYPE HTML> <html> <head> <title> JQuery | callbacks.disable() 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.disable() method"; var res = ""; var callbacks = jQuery.Callbacks(); function disable() { callbacks.disable(); } function Geeks() { // first function to be added to the list var fun1 = function(val) { res = res + "This is function 1 and value passed is " + val + "<br>"; }; // second function to be added to the list var fun2 = function(val) { res = res + "This is function 2 and value passed is" + val + "<br>"; }; callbacks.add(fun1); // adding the function 1 callbacks.fire("GFG_1"); // calling the function 1 callbacks.add(fun2); // This will not work. callbacks.fire("GFG_2"); // This will not work. el_down.innerHTML = res; } </script> </body> </html>
-
输出:
相关用法
- JQuery even()用法及代码示例
- JQuery odd()用法及代码示例
- JQuery map()用法及代码示例
- JQuery when()用法及代码示例
- JQuery get()用法及代码示例
- JQuery before()用法及代码示例
- JQuery now()用法及代码示例
- JQuery off()用法及代码示例
- JQuery die()用法及代码示例
- JQuery add()用法及代码示例
- JQuery css()用法及代码示例
- JQuery sub()用法及代码示例
- JQuery contains()用法及代码示例
- JQuery is()用法及代码示例
- JQuery append()用法及代码示例
- JQuery ajaxSuccess()用法及代码示例
- JQuery ajaxError()用法及代码示例
- JQuery trigger()用法及代码示例
- jQuery callbacks.has()用法及代码示例
注:本文由纯净天空筛选整理自PranchalKatiyar大神的英文原创作品 JQuery callbacks.disable() method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。