【问题标题】:jquery : Change background color when the function is started and completedjquery : 函数启动和完成时改变背景颜色
【发布时间】:2018-05-03 03:14:21
【问题描述】:

在我的网页中,我有一个函数 submitFileUpload(),当单击按钮 aws-upload-submit 时会调用该函数,如下面的代码所示。

<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script>
$(function() {
  submitFileUpload();
})

function submitFileUpload() {
  $('#aws-upload-submit').click(function() {
    //start displaying spinner here   
    //   $("*").css("background-color","yellow");                                                            
    loadfiles(); //around 1 min - 2 min of synchronous processing                                                               
    // $("*").css("background-color","green"); 
    //stop displaying spinner here
  })
}
  </script>
</head>

<body>
  <button type="button" id="aws-upload-submit">Submit</button>
</body>
</html>   

理想情况下,我想显示一个微调器,该微调器将在函数开始时显示,并在函数退出时隐藏。

我想到的不是微调器,而是至少更改 css 背景颜色属性。即在函数​​开始期间将背景颜色更改为黄色,最后在函数完成后将背景颜色更改为绿色。

当函数运行时,它只是显示绿色..

我在网上查找的大多数帖子都是关于 ajax 的,但在我的情况下 submitFileUpload() 不是 ajax 函数。

有没有办法改变函数开始和结束之间的背景颜色?

【问题讨论】:

  • 您需要利用 promise 来了解文件上传何时完成。您将在启动请求时设置颜色,然后从承诺中恢复返回内部的颜色。

标签: javascript jquery css


【解决方案1】:

你可以使用间隔吗?

If(loadFiles()){
setInterval(Function("changeYellow();"), 60000);
}

或者尝试使用回调函数。

【讨论】:

    猜你喜欢
    • 2011-05-16
    • 2012-02-04
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 2011-07-20
    相关资源
    最近更新 更多