javascript - 如何禁用第二次单击按钮
问题描述
我有一个在 中打开模式的按钮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
}
}
任何帮助,将不胜感激。
解决方案
因为,您已经在记录点击次数。当模式打开时禁用按钮并在模式关闭后启用它怎么样?
return <button
type='button'
className={
this.state.isModalActive ? 'disable' : ''
}
onClick={ this.handleClick }
>
确保在每次与按钮交互时更新状态isModalActive 。
推荐阅读
- intellij-idea - 如何将外部应用程序集成到 IntelliJ 插件中?
- python - 使用继承在不同类之间共享数据
- java - 构建 Minecraft Forge 1.17.1 MDK 时出现“Content-Length delimited message body”错误
- r - 返回新数据框,其中包含在 R 中使用用户给定名称的函数内创建的列
- html - 如何在角度表行中仅显示和维护一次数据状态
- macos - Visual Studio Code 中的 Flutter SDK 路径问题
- node.js - 我试图通过 npm install -g json-server 来 json-server,但每次我得到一个错误
- apache - 将查询参数转发到 .htaccess 文件中的 ErrorDocument
- python - 无法确定关系 Product.collections 上的父/子表之间的连接条件
- python - 如何修复 405 Method Not Allowed Flask 错误?