如何禁用第二次单击按钮

问题描述 投票:1回答:2

我有一个按钮在framework7中打开一个模态,但是如果双击则模式打开两次,我试图不允许双击该按钮而没有运气。

$(Button, {
  fill: true,
  raised: true,
  noFastClick: true,
  onClick: this.handle_click
})

const clickTimes: any[] = []

handle_click = (button) => {
   const clickTime = new Date().getTime()
   clickTimes.push(clickTime)
   if (clickTimes.length > 1) {
       console.log("double click detected")
       button.disabled = true
       clickTimes.length = 0
       return
   }
}

任何帮助,将不胜感激。

javascript reactjs ecmascript-6 ecmascript-5 html-framework-7
2个回答
0
投票

您可以检查事件的detail属性是否为1,这意味着它不是双击的第二次单击。

If (e.detail !== 1) { return }

或使用类似lodashthrottle

handle_click = _.throttle(func, 500)

这将确保每个500ms最多一次调用该函数


0
投票

因为,您已经记录了点击次数。如何在打开模态时禁用按钮,并在模态关闭后启用它?

return <button
  type='button'
  className={
    this.state.isModalActive ? 'disable' : ''
  }
  onClick={ this.handleClick }
>

确保在每次与按钮的交互时更新状态isModalActive。

© www.soinside.com 2019 - 2024. All rights reserved.