【发布时间】:2015-10-12 10:47:52
【问题描述】:
当我在后台计算时,我正在使用这个javascript 来显示一个隐藏的 div 以显示加载消息:
<script src="Scripts/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function ShowProgress() {
setTimeout(function () {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.show();
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left });
}, 200);
}
$('form').live("submit", function () {
ShowProgress();
});
</script>
据我了解,如果触发提交,脚本将始终运行
$('form').live("submit", function () {
ShowProgress();
});
我必须如何更改代码以仅在单击特定按钮时运行?
我尝试在单击按钮时加载它(注释掉$('form').live("submit",...)
protected void btn_start_Click(object sender, EventArgs e)
{
string script = "<script type=\"text/javascript\"> ShowProgress(); </script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", script);
}
加载 div 正在显示,但从未停止。我有什么要改变的?谢谢
更新
忘记if (!IsPostBack)中的代码了:
string script = "$(document).ready(function () { $('[id*=btnSubmit]').click(); });";
ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);
【问题讨论】:
-
仅供参考:
live在 jQuery 中已被弃用,并在所有当前版本中被删除。可能是升级到现代版本的好时机。 -
@epascarello 好的,谢谢,我会更新 :)
标签: javascript