Input Fires Keypress Event Twice

后端 未结 8 2210
小蘑菇
小蘑菇 2021-02-18 14:26

This question has been asked/answered (mostly) before, BUT I\'ve tried three things to stop the event from bubbling but nothing has worked:

return false;
e.stopPr         


        
相关标签:
8条回答
  • 2021-02-18 15:01

    I had same issue and I used above method and it work for me.

    $(document).unbind('keypress').bind('keypress', function (e) {
       // some logic here
    });
    
    0 讨论(0)
  • 2021-02-18 15:10

    Try unbinding the event first then bind it, refer below code:

    $('.addField').show().unbind('keyup').keyup(function(event){
     event.preventDefault();
    
      if(event.keyCode == 13 || event.keyCode==9) {
    ProfilePage.createTag( this, 'nada', 'addField')
        $(this).hide().val('');
    
        return false;       
    }
    

    An explanation is here, i had written a post about this on my new blog.

    0 讨论(0)
提交回复
热议问题