jQuery Set wait time before a function executes
-
03-06-2021 - |
Domanda
How can i set wait time for this function.
function UpdateMedicaitonHistory(data) {
MedicaitonHistoryGrid();
//set a wait time to finish MedicaitonHistoryGrid() like for 3 seconds
// then execute the below code.
if ($("#MedHistoryGridSec").is(":visible")) {
alert("yes we have grid");
}
else{
alert("No Grid");
}
}
Soluzione
You can use setTimeout
:
setTimeout(function()
{
if($('#MedHistoryGridSec').is(':visible'))
alert('yes');
else
alert('no');
}, 3000);
Altri suggerimenti
You could wrap up the code in a callback function and run it after three seconds using window.setTimeout
:
var afterThreeSeconds = function() {
if ($("#MedHistoryGridSec").is(":visible")) {
alert("yes we have grid");
}
else{
alert("No Grid");
}
}
window.setTimeout(afterThreeSeconds, 3000);
Can you add a parameter to the medication history grid function taking a function containing the code you want executed after that function succeeds which you can then call at the end of the medication history grid function?
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow