用Enter键提交表单而不提交按钮? [英] Submit form with Enter key without submit button?

查看:169
本文介绍了用Enter键提交表单而不提交按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:


如何在文本输入框中使用Enter键提交表单,而无需添加提交按钮?

我记得过去曾经工作过,但现在我测试了它,除非它里面有提交类型的输入字段,否则表单不会被提交。

  $(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();
    }
});

这篇关于用Enter键提交表单而不提交按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆