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

前端 未结 7 2051
孤独总比滥情好
孤独总比滥情好 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:53

    Change your click handler to:

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

    then you can use .off(), with name spaced event names:

    $(document).off('click.myevent', '.form-template-name');
    

提交回复
热议问题