Javascript:单击ID后,在1秒钟内禁用click事件 [英] Javascript: Disable the click event for 1 second after an ID is clicked
本文介绍了Javascript:单击ID后,在1秒钟内禁用click事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
标题几乎描述了我的问题.我只需要精确地禁用click事件一秒钟,这样我就不能在这么短的时间内单击网页上的任何其他按钮. 时间过去之后,我可以再次单击任何地方.
Title pretty much describes my problem. I just need to disable the click event for precisely one second, so that I couldn't click on any other buttons on the webpage for that small duration. After the time gets over, I could click anywhere again.
禁用其他按钮一秒钟也是可以的.
Disabling other buttons for that one second is also acceptable.
推荐答案
尝试一下,
$('#id').on('click',function(){
// let a common class(disable-btn) for each button which should be disabled for on second
$('.disable-btn').prop('disabled',true);
setTimeout(function(){
// enable click after 1 second
$('.disable-btn').prop('disabled',false);
},1000); // 1 second delay
});
$('#id').on('click', function() {
// let a common class(disable-btn) for each button which should be disabled for on second
$('.disable-btn').prop('disabled', true);
setTimeout(function() {
// enable click after 1 second
$('.disable-btn').prop('disabled', false);
}, 1000); // 1 second delay
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="id">Click to disable other for 1 second</button>
<br/>
<button class="disable-btn">Will Disable for 1 sec</button>
<br/>
<button class="disable-btn">Will Disable for 1 sec</button>
<br/>
<button>Will not Disable</button>
<br/>
<button class="disable-btn">Will Disable for 1 sec</button>
<br/>
您可以通过添加class="disable-btn"
这篇关于Javascript:单击ID后,在1秒钟内禁用click事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文