js给元素添加禁止点击事件

JavaScript09

js给元素添加禁止点击事件,第1张

var selectBleedingWayBox = document.getElementById("selectBleedingWayBox" + dev.DeviceId)

/ 判断条件 /

if (dev.TrainingState == 'Start') {

/ 添加禁用点击事件class /

selectBleedingWayBox.classList.add("mouseDisabled")

} else {

/ 删除禁用点击事件class /

selectBleedingWayBox.classList.remove("mouseDisabled")

}

前几天遇到了一个关于前端重复点击事件问题,防止用户恶意操作,重复点击按钮事件,有二个逻辑解决此问题:

1.

2.定义变量保存每次点击的时间,上次和当前次点击的时间间隔小于某个时间,就return掉,否则就继续之后步骤,类似于

this.state={clickTime:new Date().getTime()}

  buyCard(){ 

   var {clickTime} =this.state

    var nowTime = new Date().getTime()

     if( clickTime != 'undefined'&& (nowTime - clickTime <500)){

               return false

     }else{

        this.setSate({clickTime:nowTime})

        .....

     }       

}