Textarea submit with enter

2019-08-12 03:26发布

问题:

I have a form. When you hit the enter button. The form is going submit. But now i have a problem. When i hit the enter button in the textarea. Then the form is going submit. But in a textarea, a enter must be a enter.

How can i fix this? This is my code:

form.keypress(function(e) {
    if (e.which == enter) {
        e.preventDefault();
        $(this).find('[type=submit]').click();
    }
});

回答1:

Try like this

form.submit(function(e) {
    e.preventDefault();              
    $(this).find('[type=submit]').click();
    $("form").submit();       
})


回答2:

Try

$("input:submit").live('click',function(){         
     $("form").submit();
})