1、节流
创建一个div
<div class="boss">1</div>
js控制
var boss=document.querySelector(".boss");
/*获取*/
var num=parseInt(boss.innerHTML);
/*转类型*/
var bossTime=null;
var bol=true;
boss.onclick=function () {
if(bol){
bol=false;
bossTime=setTimeout(function () {
num++;
boss.innerHTML=num;
bol=true;
},1000)
}
}
2、防抖
boss.onclick = function(){
clearTimeout(bossTime);
if(bol){
num++;
boss.innerHTML = num;
bol=false;
}else{
bossTime = setTimeout(function(){
bol = true;
},1000)
}
}