我有一个按钮在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
}
}
任何帮助,将不胜感激。
您可以检查事件的detail
属性是否为1
,这意味着它不是双击的第二次单击。
If (e.detail !== 1) { return }
或使用类似lodash
的throttle
handle_click = _.throttle(func, 500)
这将确保每个500ms
最多一次调用该函数
因为,您已经记录了点击次数。如何在打开模态时禁用按钮,并在模态关闭后启用它?
return <button
type='button'
className={
this.state.isModalActive ? 'disable' : ''
}
onClick={ this.handleClick }
>
确保在每次与按钮的交互时更新状态isModalActive。