<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="checkbox" id="1">
<input type="checkbox" id="2">
<input type="checkbox" id="3">
<input type="checkbox" id="4">
<input type="checkbox" id="5">
<input type="checkbox" id="6">
<input type="checkbox" id="7">
<input type="checkbox" id="8">
<input type="checkbox" id="9">
<input type="checkbox" id="10">
<p id="status"></p>
<script>
var checkbox = document.getElementsByTagName('input'); //本体类,同步逻辑处理
var syncFile = function(id){
//Ajax等同步代码...
document.getElementById('status').innerHTML = '正在同步文件'+id;
} //代理类,通过一个闭包结构保存cache和timer
var syncFileProxy = (function(){
var cache = [];
var timer = null; return function(id){
cache.push(id);
//小于2秒的同步请求,则不会处理
if(timer){
return;
}
timer = setTimeout(function(){
syncFile(cache.join(','));
clearTimeout(timer); //清除定时器
timer = null; //重置变量
cache = []; //重置cache数组
},2000);
}
})(); for(var i = 0; i < checkbox.length; i++){
checkbox[i].onclick = function(){
if(this.checked === true){
syncFileProxy(this.id);
//可以随时替换成 syncFile(this.id)
}
}
}
</script>
</body>
</html>

最新文章

  1. Microsoft Azure News(6) Azure新F系列虚拟机
  2. Linux下EclipseCDT工程和TFS的持续集成CI实践
  3. JAVA面试题之实现字符串的倒序输出
  4. Win7+VMware Workstation环境下的CentOS-Linux网络连接设置
  5. poj 1330 Nearest Common Ancestors LCA
  6. Java再学习——sleep(), wait(), notify(), notifyAll()
  7. iOS开发中EXC_BAD_ACCESS的另类原因
  8. Js正则表达式提取图片地址
  9. 何使用CSS写出一个下拉菜单。
  10. hive udaf 用maven打包运行create temporary function 时报错
  11. 通过js来设置cookie和读取cookie,实现登陆时记住密码的功能
  12. JS性能优化之怎么加载JS文件
  13. ROS_Kinetic_28 turtlebot gazebo demo例子
  14. Java:接口和抽象类,傻傻分不清楚?
  15. SpringBoot之配置
  16. U3D一些使用
  17. 非常干货之Python资源大全
  18. Flask学习【第5篇】:用Falsk实现的分页
  19. 呼叫WCF Service的方法出现Method not allowed异常
  20. [git hooks] pre-commit 配置

热门文章

  1. npm 私有模块的管理使用
  2. XStream将java对象转换为xml时,对象字段中的下划线“_”,转换后变成了两个的解决办法
  3. 旺财速啃H5框架之Bootstrap(一)
  4. UWP开发之ORM实践:如何使用Entity Framework Core做SQLite数据持久层?
  5. 免费开源的.NET多类型文件解压缩组件SharpZipLib(.NET组件介绍之七)
  6. 内存映射文件MemoryMappedFile使用
  7. .NET设计模式访问者模式
  8. 关于MJRefresh的下拉加载数据bug
  9. SVN的使用
  10. SQL数据类型