Best way to remove an event handler in jQuery?

前端 未结 20 2328
庸人自扰
庸人自扰 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 11:58

    If event is attached this way, and the target is to be unattached:

    $('#container').on('click','span',function(eo){
        alert(1);
    
        $(this).off(); //seams easy, but does not work
    
        $('#container').off('click','span'); //clears click event for every span
    
        $(this).on("click",function(){return false;}); //this works.
    
    });​
    

提交回复
热议问题