我有以下jquery註冊一個計時器間隔每10秒發生在網頁每當一個輸入按鈕被稱爲btnExport被點擊。如何有條件地註冊window.setInterval onload
if ($) {
$(document).ready(function() {
$("input[id$='btnExport']").click(function ($e) {
// javascript timer function
window.setInterval(ExportProgressCheck, 10000);
});
function ExportProgressCheck() {
$.ajax({
type: "POST",
url: "DMZ_Export.aspx/GetExportProgress",
contentType: "application/json; charset=utf-8",
data: "",
dataType: "json",
success: AjaxSuccess,
error: AjaxFailed
});
}
});
}
但是,在某些情況下,我需要計時器間隔在加載頁面加載時立即開始計時。我的問題是,我不知道如何從代碼隱藏的頁面加載事件中執行此操作。從理論上講它會去像...
protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
if (IsExportInProgress()) {
// Register the timer interval now!! How do I do this??
// window.setInterval(ExportProgressCheck, 10000);
}
}
}
}
我試圖通過註冊一個啓動腳本來做到這一點,但它不喜歡的劇本,因爲它不知道ExportProgressCheck是什麼...
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(cstype, csname1,
"<script type=\"text/javascript\">window.setInterval(ExportProgressCheck, 10000);</script>",
false);
對此的任何幫助將不勝感激!謝謝!
您已將它附加到document.ready,意思是onDomReady。你可以嘗試附加到window.load,但我沒有看到問題。 – Zirak 2011-04-20 21:19:05