如何设置 click() Jquery 事件延迟再次点击?

How to set a click() Jquery event delay to click again?

我正在尝试为我的点击事件设置延迟时间以再次点击,以防止在不到 200 毫秒的时间内进行多次点击。示例:

(delay 200ms){ 
    $('#button').click(function(){
    });

}

您可以重新绑定点击事件setTimeout并在点击处理程序中取消绑定(每当下一次点击发生时) 喜欢

function bindClick(){
    $('#button').bind('click',function(){
        ...click code here...

        $('#button').unbind('click');
       setTimeout(bindClick, 200);
    });
}

请注意,这不会每 200 毫秒重新绑定一次,只有在发生点击时才会重新绑定。

DEMO

$("#buttonid").click(function(){
   //do stuff
  $(this).prop('disabled', true);
   setTimeout(function(){
      $(this).prop('disabled', false);
  }, 500);
});