簡體   English   中英

jQuery設置函數執行前的等待時間

[英]jQuery Set wait time before a function executes

如何設置此功能的等待時間。

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

您可以使用setTimeout

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

您可以將代碼包裝在回調函數中,並在三秒鍾后使用window.setTimeout運行它:

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

window.setTimeout(afterThreeSeconds, 3000);

您是否可以使用包含要在該功能成功后執行的代碼的功能,向葯物歷史記錄網格函數添加參數,然后可以在葯物歷史記錄網格函數的末尾調用該代碼?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM