如何在按下回车键时提交表单? [英] How to submit a form when the return key is pressed?

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

问题描述

有人可以告诉我如何在按下回车键并且表单中没有按钮时提交HTML表单吗?
提交按钮不存在。我使用的是自定义div而不是。

解决方案

IMO,这是最干净的答案:

< form action =method =get>名称:< input type =textname =name/>< br />密码:< input type =passwordname =password/>< br /> < div class =yourCustomDiv/> < input type =submitstyle =display:none/>< / form>

b
$ b

更好的是,如果您使用javascript使用自定义div提交表单,则还应该使用javascript创建它,并在按钮上设置display:none样式。这样,禁用javascript的用户仍然可以看到提交按钮并点击它。






已经注意到显示器:不会导致IE忽略输入。我创建了一个以标准表单开始的新的JSFiddle示例,并使用渐进式增强来隐藏提交和创建新的div。我确实使用了 StriplingWarrior


Can someone please tell me how to submit an HTML form when the return key is pressed and if there are no buttons in the form? The submit button is not there. I am using a custom div instead of that.

解决方案

IMO, this is the cleanest answer:

<form action="" method="get">
  Name: <input type="text" name="name"/><br/>
  Pwd: <input type="password" name="password"/><br/>
  <div class="yourCustomDiv"/>
  <input type="submit" style="display:none"/>
</form>

Better yet, if you are using javascript to submit the form using the custom div, you should also use javascript to create it, and to set the display:none style on the button. This way users with javascript disabled will still see the submit button and can click on it.


It has been noted that display:none will cause IE to ignore the input. I created a new JSFiddle example that starts as a standard form, and uses progressive enhancement to hide the submit and create the new div. I did use the CSS styling from StriplingWarrior.

这篇关于如何在按下回车键时提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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