Form doesn't work without double click

不问归期 提交于 2019-12-13 20:40:04

问题


I have a problem with a form function in jQuery. It forces me to double click in order to submit the form.

<script>  
function pin_login(forma) {
    jQuery("#form_" + forma).submit(function (e) {

        var value_pin = jQuery(".pin_" + forma).val();
    });
}
</script>

Every time I double click it works, but it doesn't work when I single click, it doesn't submit the form. To clarify, I want it to submit one a single click, not a double.


回答1:


Because you call e.preventDefault() your form should not return after second or third or nth clicking of submit.

If you want to submit you need to return true without calling e.preventDefault() like in the example below.

$("form").submit(function() {
  if ( correct )
     return true;
  else {
     $("#error").text("Not valid!") ;
     return false;
  }
});

Calling e.preventDefault() or returning false will prevent submitting your form to the server.

Now, since e.preventDefault() prevents form submitting and you claim that your form does it, so I claim that your code from the example is never called. Can you copy paste more, please? Or maybe you can use jsfiddle...



来源:https://stackoverflow.com/questions/18540083/form-doesnt-work-without-double-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!