【问题标题】:How could I start a loading spinner after submitting a form and during running the script and stop loading after script finishes?如何在提交表单后和运行脚本期间启动加载微调器并在脚本完成后停止加载?
【发布时间】:2017-09-24 23:24:40
【问题描述】:

我有一个带有提交输入的表单

<input type="submit" class="download">

它负责运行下载一些文件的 php 和 java 脚本,我想在单击按钮时在按钮上启动加载微调器,并在脚本运行时继续。

这是加载函数,它适用于特定的超时,我希望它或类似的函数在运行脚本期间一直工作,直到它完成运行。

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

【问题讨论】:

  • 如何确定脚本何时完成任务?您可以在问题中包含完整的代码吗?见stackoverflow.com/help/mcve
  • 使用任意spinner的gif格式图片,默认设置为display:none。然后在单击按钮时将display 更改为block。然后在脚本加载完成后将其设置回display:none

标签: javascript php jquery html ajax


【解决方案1】:

结帐ladda.js 以获得漂亮的按钮微调器示例

$('.download').on('click', function() {

    var $this = $(this);
    $this.button('loading');
    // Run your script here
    $this.button('reset');

);

或者如果您的脚本有异步回调,请改为:

$('.download').on('click', function() {

    var $this = $(this);
    $this.button('loading');

    runMyScript(function() {
        $this.button('reset');
    });
);

【讨论】:

  • 既是javascript又是php脚本
  • 你是先提交表单,然后点击clciked中的提交按钮,还是调用一个JS来做点什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多