jQuery callbacks.disabled()方法
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>
输出: