按“Enter”键按钮提交表单?
我有一个登录表单,我试图在按下输入按钮时(填写完毕后)提交它。我很擅长使用 jQuery。我该怎么做?
I have a login form, and I'm trying to have it submit when I press the enter button (after having filled it out). I'm fine with using jQuery. How would I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要您专注于其中一个字段并按 Enter 键,它就会提交。这是我所知道的所有浏览器的默认行为。实际上,您不需要像其他人所说的那样
,但您当然应该(并且可能需要)。
如果您想要这种行为而不关注输入,则只需要 javascript,但我强烈建议您不要这样做,因为没有人会期待它。只需让用户按照他们习惯的方式与表单交互即可,这并不奇怪。
As long as you are focused on one of the fields and hit enter, it will submit. This is the default behavior for all browsers that I know of. You actually don't need the
<input type="submit" />
as others have said, but of course you should (and probably do).You only need javascript if you want this behavior without focusing on an input, but I would strongly advise against it because no one will be expecting it. Just let users interact with the form the way they are used to, no surprises.