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>
輸出:
相關用法
- JQuery css()用法及代碼示例
- JQuery get()用法及代碼示例
- JQuery add()用法及代碼示例
- JQuery contains()用法及代碼示例
- JQuery die()用法及代碼示例
- JQuery is()用法及代碼示例
- JQuery odd()用法及代碼示例
- JQuery map()用法及代碼示例
- JQuery now()用法及代碼示例
- JQuery before()用法及代碼示例
- JQuery even()用法及代碼示例
- JQuery off()用法及代碼示例
- JQuery extend()用法及代碼示例
- JQuery trim()用法及代碼示例
- jQuery callbacks.has()用法及代碼示例
- JQuery ajax()用法及代碼示例
- JQuery escapeSelector()用法及代碼示例
- JQuery makeArray()用法及代碼示例
- JQuery isEmptyObject()用法及代碼示例
注:本文由純淨天空篩選整理自PranchalKatiyar大神的英文原創作品 jQuery callbacks.disabled() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。