Jquery - page reload

I have Textboxboth Button(Next and Previous) displayed in Lightbox. My page is currently reloading after pressing the Enter key. I do not want this to happen.

What I want, when I press the Enter key, I should click the "Next" button without reloading the page that is back in the lightbox.

I used the following code, but it occurs as reloadwell as clickthe following buttons:

$("input").bind('keyup', function(event){
    if(event.keyCode == 13){
        $("#nextbtn").trigger('click');
    }
    event.preventDefault();
    return false;
});
+3
source share
4 answers

Make sure your enter button is a button type and not send

<input type='button'>

, 13, nextbtn click, false, .

$("input").bind('keyup', function(event){ 
  if(event.keyCode == 13){ 
      $("#nextbtn").click(); 
      return false;
  }
});
+5

return false statement, :

$("input").bind('keyup', function(event){ 
    if(event.keyCode == 13){ 
        $("#nextbtn").trigger('click');
        return false; 
    } 
    event.preventDefault(); 
});
0

, , , iFrame. DOM, . - jquery.form AJAX.

0

. , , , - . , click, keyup. :

Firstly. Assign an event to a clickbutton that returns false. Secondly. Change your input event on keypressinstead keyupand add another line: e.stopPropagation().

0
source

Source: https://habr.com/ru/post/1729177/


All Articles