[英]How to disable this button for 5 sec after first click?
在我的代碼中,單擊按鈕.getmore向下滾動。 它從數據庫加載數據。 每次單擊后,我需要將其禁用5秒鍾。 如何設置此延遲計時器?
還是有可能在啟動后禁用此功能5秒鍾? 禁用該按鈕或禁用該功能對我而言將起作用。
$(window).scroll(function(){
if ($(document).height() <= $(window).scrollTop() + $(window).height()) {
// Here how can i set a delay time of 5 sec before next click
$('.getmore').click();
}
});
您可以使用jQuery的setTimeout()函數。
$('.getmore').prop('disabled', true);
setTimeout(function() {
$('.getmore').prop('disabled', false);
}, 5000);
一種解決方案是使用setTimout並使用document.getElementById("yourButtonID").disabled = true;
禁用具有javascript的按鈕 document.getElementById("yourButtonID").disabled = true;
之后,您可以使用setTimeout()n,在其中放入禁用按鈕功能。
setTimeout(document.getElementById('ur_button_id')。style.display ='none',500);
您可以在clickHandler中使用一個標志:
var clickHandler = () => { if (clickHandler.running) return clickHandler.running = true setTimeout(() => { clickHandler.running = false }, 5000) console.log(new Date()) } $('#getmore').click(clickHandler)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id='getmore'>more</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.