javascript - Unexpected submit on "submit" button click -


If I activate the button (with the tab button), and then Enter , the keyboard handler will set fire, and click on the button will generate the event. But the OnClick will submit and the handler will not fire it will just silently post the form. Why?

  & lt; Script src = "../js/jquery.js" type = "text / javascript" & gt; & Lt; / Script & gt; & Lt; Script type = "application / javascript" & gt; $ () Ready (function () {$ ("# F1") .press (function (event) {if (event.keyCode == 13) {var currentInputId = $ (event) [0]. Target.id; Var currentInput = $ ('#' + Current input id); Current input.Click (); Return back;}}); $ ("#F1"). Submit (function () {Alert ("huy"}}}) & Lt; / script & gt; form name = "f1" id = "f1" method = "post" & gt; & gt; input type = "text" & gt; & gt; input type = "submit "Onclick =" return false; "id =" presented ">     

rewritten from scratch
  • handler Click the call button

  • button onclick return false
  • event handling stop (Form not submitted)

    If I delete onclick = "return false"; , then

    • keypress handler runs and click on call button Form without submit handler is called

      Some more tests indicate that submit Handler is not being called * because you come back from false to keypress handler.

      Then, the problem to resolve:

      1. button onclick = "return false"; Remove
      2. Remove false false questions handler

        will display this alert and then submit the form Will submit as you expect it.

Comments