标题几乎描述了我的问题。我只需要恰好禁用点击事件一秒钟,这样我就无法在这么短的时间内点击网页上的任何其他按钮。 时间结束后,我可以再次点击任意位置。
禁用其他按钮一秒钟也是可以接受的。
最佳答案
尝试一下,
$('#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"
来禁用 #id
按钮本身
关于Javascript:点击ID后禁用点击事件1秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32002366/