JQuery脚本加载时序 [英] JQuery Script Load Timing

查看:58
本文介绍了JQuery脚本加载时序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个设置jquery脚本的按钮,有没有办法确保该按钮在脚本完成之前处于非活动状态?

If I have a button that sets off a jquery script is there a way to make sure the button is inactive until the script completes?

推荐答案

在脚本开头的某个地方(可能是按钮的click事件),将按钮的disabled属性设置为true:

Somewhere at the beginning of your script (probably on the button's click event), set the button's disabled attribute to true:

$("#mybutton").attr("disabled", true);

然后,完成后,删除该属性:

Then, when complete, remove that attribute:

$("#mybutton").removeAttr("disabled");

编辑:

如果你想得到(略微)幻想,在你工作的时候改变按钮的文字。如果是图像按钮,您可以将src更改为友好的请稍候消息。以下是按钮文本版本的示例:

If you want to get (slightly) fancy, change the text of the button while you're doing the work. If it's an image button, you can change the src to a friendly "please wait" message. Here's an example of the button text version:

$("#mybutton").click(function() {
  var origVal = $(this).attr("value");

  $(this).attr("value", "Please wait...");
  $(this).attr("disabled", true);

  //Do your processing.

  $(this).removeAttr("disabled");
  $(this).attr("value", origVal);
});

这篇关于JQuery脚本加载时序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆