[英]How to disable the second click on a button
我有一個在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 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.