JQuery deferred.resolve()方法
JQuery的这个deferred.resolve()方法是用来解决一个递延对象和调用任何给定参数的doneCallbacks。
语法:
deferred.resolve([args])
参数:
- args: 这是可选的参数,是传递给dedCallbacks的参数。
返回值:该方法返回递延对象。
下面讨论两个例子。
- 例子。在这个例子中,Resolve()被调用,其参数是:
<!DOCTYPE HTML>
<html>
<head>
<title>
JQuery | deferred.resolve() 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.resolve() method";
function Func(val, div){
(div).append(val);
}
function Geeks() {
var def =.Deferred();
def.done(Func);
def.resolve(
'resolve() method is called with arguments
and Deferred object is resolved', '#GFG_DOWN')
}
</script>
</body>
</html>
-
输出:
-
例子。在这个例子中,Resolve()被调用,没有参数。
<!DOCTYPE HTML>
<html>
<head>
<title>
JQuery | deferred.resolve() 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.resolve() method";
function Func(){
('#GFG_DOWN').append(
"resolve() method is called without arguments
and Deferred object is resolved");
}
function Geeks() {
var def =.Deferred();
def.done(Func);
def.resolve()
}
</script>
</body>
</html>
- 输出: