Something like this will works only when user clicks the anchor. But a form also is submitted when user push [enter] key inside the form. How could I have the same functionality using just an anchor?
$('a.submit').click(function() {
$(this).closest('form').submit();
});
Thanks.-
EDIT (with solution):
This combination works (at least) in FF and chrome! either clicking the anchor with class submit or pressing [e开发者_JAVA技巧nter].
$('#my_form a.submit').click(function(e) {
e.preventDefault();
$(this).closest('form').submit();
});
$('#my_form').keydown(function(e) {
if (e.keyCode != 13)
return;
$(this).submit();
});
Thanks for your comments!
Need to prevent the click event from firing the anchor:
$('a.submit').click(function(event) {
event.preventDefault();
$(this).closest('form').submit();
});
After several test this is perfectly working:
$('#my_form a.submit').click(function(e) {
e.preventDefault();
$(this).closest('form').submit();
});
$('#my_form').keydown(function(e) {
if (e.keyCode != 13) // Enter or Return keystroke
return;
$(this).submit();
});
精彩评论