jQuery设置函数执行前的等待时间

时间:2012-04-25 17:30:10

标签: javascript jquery time-wait

如何设置此功能的等待时间。

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");
    }
}

3 个答案:

答案 0 :(得分:9)

您可以使用setTimeout

setTimeout(function()
{
     if($('#MedHistoryGridSec').is(':visible'))
         alert('yes');
     else
         alert('no');
}, 3000);

答案 1 :(得分:0)

您可以在回调函数中包装代码,并在使用window.setTimeout三秒后运行它:

var afterThreeSeconds = function() {
  if ($("#MedHistoryGridSec").is(":visible")) {
    alert("yes we have grid");
  }
  else{
    alert("No Grid");
  }
}

window.setTimeout(afterThreeSeconds, 3000);

答案 2 :(得分:0)

您是否可以在药物历史网格功能中添加一个参数,该功能包含您在该功能成功后要执行的代码,然后您可以在药物历史网格功能结束时调用该功能?

相关问题