How to remove $(document).on click event?

前端 未结 7 1994
孤独总比滥情好
孤独总比滥情好 2021-01-06 08:13

Here is the code to add event

   $(document).on({
      click: function() {
        $(this).hide();
        $(\'#form_name\').removeClass(\'hide\');
                 


        
7条回答
  •  醉梦人生
    2021-01-06 08:50

    You can try with:

    var clickEvent = function() {
        $(this).hide();
        $('#form_name').removeClass('hide');
        $('#form_template_name')
          .attr('placeholder', $(this).text())
          .focus();
    };
    
    $(document).on({
       click: clickEvent         
    }, '.form-template-name');
    

    And unbind it with:

    $(document).unbind('click', clickEvent);
    

提交回复
热议问题