zhourongcode

在下载或者上传文件过程中避免重复点击带来的多次同样的请求造成资源浪费,限制 button 的点击次数是很有必要的。 1. 增强用户体验,2. 减轻服务器压力。

HTML 代码

<button id = "test">下载或上传按钮</button>

JS 代码

var foo = function(element) {
  var intent = document.querySelector(element)
  intent.disabled = \'disabled\'
  setTimeout(function() {
    intent.disabled = \'\'
  }, 3000) /* 可以把 3000 改成自定义的时间*/
  console.log(\'3 秒内不可以重复点击\')
}


var bar = function(fun, select) {
  var intent = document.querySelector(\'#test\')
  intent.addEventListener(\'click\', function() {
    fun(select)
  })
}

bar(foo, "#test")

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
猜你喜欢
  • 2021-11-17
  • 2021-11-25
  • 2021-12-18
  • 2022-12-23
  • 2021-05-31
  • 2021-11-03
  • 2022-12-23
相关资源
相似解决方案