JQuery deferred.state()方法
JQuery的这个deferred.state()方法是用来确定一个递延对象的当前状态。
语法:
deferred.state()
JavaScript
返回值:该方法返回递延对象的状态。
下面讨论两个例子。
- 例子。在这个例子中,递延对象’def’的状态是待定。
<!DOCTYPE HTML>
<html>
<head>
<title>
JQuery | deferred.state() 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");
el_up.innerHTML = "JQuery | deferred.state() method";
var def = .Deferred();
function Geeks() {
('#GFG_DOWN').text('deferred state is ' + def.state());
}
</script>
</body>
</html>
HTML
-
输出:
-
例子。在这个例子中,递延对象’def’的状态是待定的,通过点击按钮,它改变为解决。
<!DOCTYPE HTML>
<html>
<head>
<title>
JQuery | deferred.state() 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");
el_up.innerHTML = "JQuery | deferred.state() method";
var def = .Deferred();
def.always(Func);
('#GFG_DOWN').append(
'Deferred state is ' + def.state() + '</br>');
function Func(val, div){
(div).append(val);
}
function Geeks() {
def.resolve(
'Our deferred is resolved now. <br />', '#GFG_DOWN');
('#GFG_DOWN').append(
'Current state of deferred is ' + def.state() + ' <br />');
}
</script>
</body>
</html>
HTML
- 输出: