[英]Do jQuery functions return a value like Javascript? How?
In Javascript we can declare a variable and we can call a function. 在Javascript中,我们可以声明变量,也可以调用函数。 The function will return a value and will be assigned to the variable. 该函数将返回一个值,并将其分配给该变量。 Is this possible in jQuery? 在jQuery中这可能吗?
I want to know if my previous function is finished or not. 我想知道我以前的功能是否完成。 I want to get the result success or failure and call another function based on first function's result 我想获得结果成功或失败,并根据第一个函数的结果调用另一个函数
I use a function setTimeout
for blockUI
. 我对blockUI
使用setTimeout
函数。
How can I check if that timeout is due to another function? 如何检查该超时是否归因于其他功能?
Do .val
or $.get
work for the above purposes? .val
或$.get
是否可以$.get
上述目的?
UPDATE: Based on your comments... 更新:根据您的评论...
First question: 第一个问题:
You should probably look at some of the blockUI demos . 您可能应该看一些blockUI演示 。
It looks like blockUI
has a callback onBlock:
that calls a function after the fadeIn
is done. 看起来blockUI
有一个回调onBlock:
在fadeIn
完成后调用一个函数。
onBlock: function() {
alert('Page is now blocked; fadeIn complete');
}
Second question: 第二个问题:
jQuery is just a library of javascript code, therefore you can assign functions to variables the same way you always do. jQuery只是一个JavaScript代码库,因此您可以像往常一样将函数分配给变量。
var a = function dosome() {
// do something
};
a(); // call the function
Third question: 第三个问题:
You mean you want to redirect after the 3000ms fadeIn
of the blockUI
? 你的意思是你想要的3000ms后重定向fadeIn
的的blockUI
? You would do it in the callback that I pointed out under question 1 above. 您可以在我在上面问题1下指出的回调中进行操作。 But of course this will make the entire page change, including the blockUI
. 但这当然会使整个页面发生变化,包括blockUI
。
window.location = "http://somedomain.com/some/path";
Some clarification in your question is needed. 您的问题需要一些澄清。
It sounds like you have a function that sets a setTimeout()
for some purpose, and that function is reused, so you need to reference the correct instance of setTimeout()
. 听起来您有一个出于某种目的设置setTimeout()
的函数,并且该函数已被重用,因此您需要引用setTimeout()
的正确实例。
If so, you can have your function return the setTimeout()
instance, and use that reference to clear it if needed. 如果是这样,您可以让函数返回setTimeout()
实例,并在需要时使用该引用将其清除。
function unblockUI(dur) {
return setTimeout(function() {
$.unblockUI();
}, dur);
}
var someTimeout = unblockUI(1000);
clear(someTimeout);
var someOtherTimeout = unblockUI(1000);
clear(someOtherTimeout);
Is this close to what you're asking? 这接近您的要求吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.