问题
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