博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
限制 button 在 3 秒内不可重复点击
阅读量:4574 次
发布时间:2019-06-08

本文共 537 字,大约阅读时间需要 1 分钟。

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

HTML 代码

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")

转载于:https://www.cnblogs.com/zhourongcode/p/9070315.html

你可能感兴趣的文章
测试基础_<一>
查看>>
前端基础进阶(三):变量对象详解
查看>>
[算法]Collebarative Filtering
查看>>
clientX,screenX,pageX,offsetX的异同
查看>>
c# in out ref关键字
查看>>
day 30 客户端获取cmd 命令的步骤
查看>>
笔记javascript
查看>>
Distinct
查看>>
SQL 循环语句
查看>>
定义页面加载和导航时要执行的函数/自定义事件
查看>>
rem.js
查看>>
Unslider.js Tiny Sample
查看>>
FPGA的学习及注意事项
查看>>
面向对象内存分析
查看>>
Dijkstra BZOJ2763 [JLOI2011]飞行路线
查看>>
前端快捷键
查看>>
重新认识成功、失败、错误、平凡、笨拙
查看>>
【模板】Hash
查看>>
洛谷 1485 火枪打怪
查看>>
Fortran编译器
查看>>