Javascript 通过单击特定按钮开始加载div
当我在后台计算时,我使用这个Javascript 通过单击特定按钮开始加载div,javascript,Javascript,当我在后台计算时,我使用这个javascript来显示加载消息的隐藏div: <script src="Scripts/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function ShowProgress() { setTimeout(function () {
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(“提交”…
)
此方法将在单击特定按钮时运行(显然,您需要将我的代码中的
buttonId
替换为您所做按钮的实际id).如文档所述,live
方法将应用于提交类型的所有事件。正如其他回复所建议的,您只需选择一个元素并使用onclick
事件,或者检查事件的目标是否是您的特定按钮
我会选择前者,但这取决于您想要的行为。FYI:
live
在jQuery中已被弃用,并在所有当前版本中被删除。可能是升级到现代版本的好时机。@epascarello好的,谢谢,我将更新:)
$('form').live("submit", function () {
ShowProgress();
});
protected void btn_start_Click(object sender, EventArgs e)
{
string script = "<script type=\"text/javascript\"> ShowProgress(); </script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", script);
}
string script = "$(document).ready(function () { $('[id*=btnSubmit]').click(); });";
ClientScript.RegisterStartupScript(this.GetType(), "load", script, true);
$("#buttonId").click(function(){
ShowProgress();
});