javascript - 如何使在按钮上实现的加载旋转器在脚本运行完成后停止?

标签 javascript php jquery ajax

我有一个提交按钮,单击它即可运行脚本。

<input type="submit" value="Download Files" class="btn btn-success col-md-4"  id="load" data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Downloading Files">

$('.btn').on('click', function() {
  var $this = $(this);
  $this.button('loading');
  setTimeout(function() {
    $this.button('reset');
  }, 8000);
});

脚本运行时间不是恒定的;它不时变化。我希望加载在单击提交按钮时开始,并在脚本运行完成后结束。我怎样才能做到这一点?

最佳答案

你的代码

$('.btn').on('click', function() {    
var $this = $(this);
$this.button('loading');
setTimeout(function() {
$this.button('reset');
}, 8000);
});

需要一些补充。按以下顺序添加这些外部java脚本

Here is the working fiddle

关于javascript - 如何使在按钮上实现的加载旋转器在脚本运行完成后停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46381259/

相关文章:

php - 获取数据库实例的正确语法是什么?

通过 AJAX 的 jQuery XML : missing some nodes occasionally

jquery - .getParentNode() 在树节点超过 1k 的情况下不起作用

javascript - 无法在 jquery 中获取元素 id 的正确值

javascript - SQLite 查询在 JavaScript 中执行搜索和多个过滤器

javascript - 使用 jQuery 防止 ajax 加载页面上的脚本执行

javascript - 修改匹配的 CSS 规则

php - Shell脚本段错误

javascript - 将图像从计算机拖到div?

php - .htaccess URL 用一个和两个查询字符串变量重写