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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。