且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用Enter键提交表单而不提交按钮?

更新时间:2022-10-16 09:04:42

  $(input).presspress(function(event){
if(event.which == 13){
event.preventDefault();
$(form)。submit();
}
});


Possible Duplicate:
HTML: Submitting a form by pressing enter without a submit button

How can I submit a form with just the Enter key on a text input field, without having to add a submit button?

I remember this worked in the past, but I tested it now and the form doesn't get submitted unless there's a submit-type input field inside it.

$("input").keypress(function(event) {
    if (event.which == 13) {
        event.preventDefault();
        $("form").submit();
    }
});