我有以下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