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

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

问题描述

可能的重复:
HTML:按 Enter 提交表单,不带提交按钮

如何仅在文本输入字段上按 Enter 键提交表单,而无需添加提交按钮?

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天全站免登陆