Best way to remove an event handler in jQuery?

前端 未结 20 2371
庸人自扰
庸人自扰 2020-11-21 11:38

I have an input type=\"image\". This acts like the cell notes in Microsoft Excel. If someone enters a number into the text box that this input-image

20条回答
  •  不思量自难忘°
    2020-11-21 12:03

    Hope my below code explains all. HTML:

    (function($){
    
         $("#btn_add").on("click",function(){
           $("#btn_click").on("click",added_handler);
           alert("Added new handler to button 1");
         });
    
      
     
         $("#btn_remove").on("click",function(){
           $("#btn_click").off("click",added_handler);
           alert("Removed new handler to button 1");
         });
    
      
       function fixed_handler(){
        alert("Fixed handler");
      }
      
       function added_handler(){
        alert("new handler");
      }
      
      $("#btn_click").on("click",fixed_handler);
      $("#btn_fixed").on("click",fixed_handler);
      
      
    })(jQuery);
    
    
      
      
      

提交回复
热议问题