In Javascript we can declare a variable and we can call a function. The function will return a value and will be assigned to the variable. Is this possible in jQuery?
I want to know if my previous function is finished or not. I want 开发者_StackOverflow中文版to get the result success or failure and call another function based on first function's result
I use a function setTimeout
for blockUI
.
How can I check if that timeout is due to another function?
Do .val
or $.get
work for the above purposes?
UPDATE: Based on your comments...
First question:
You should probably look at some of the blockUI demos.
It looks like blockUI
has a callback onBlock:
that calls a function after the fadeIn
is done.
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.
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
? You would do it in the callback that I pointed out under question 1 above. But of course this will make the entire page change, including the 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()
.
If so, you can have your function return the setTimeout()
instance, and use that reference to clear it if needed.
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?
精彩评论