当我在后台计算时,我正在使用此 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);
最佳答案
$("#buttonId").click(function(){
ShowProgress();
});
只要单击特定按钮,此方法就会运行(显然您需要将我代码中的 buttonId
替换为您制作的按钮的实际 ID)。
关于javascript - 通过单击特定按钮开始加载 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31565189/