How to temporarily disable a click handler in jQuery?

前端 未结 12 2028
不思量自难忘°
不思量自难忘° 2020-12-04 14:02

Say I have something like the following to trap the click event of a button:

$(\"#button_id\").click(function() {
  //disable click event
  //do something
           


        
12条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-04 14:34

    $("#button_id").click(function() {
      if($(this).data('dont')==1) return;
      $(this).data('dont',1);
      //do something
      $(this).data('dont',0);
    }
    

    Remeber that $.data() would work only for items with ID.

提交回复
热议问题