按Enter键提交一个输入的HTML表单,但不是两个 [英] Pressing enter submits HTML form with one input, but not two

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

问题描述

任何人都可以解释这种行为吗?按下HTML表单的文本框中的Enter键将在表单包含单个文本框时提交表单,但当表单包含两个或更多个文本框时不会提交表单。



jsFiddle (一个输入): http://jsfiddle.net/gpPTa/

jsFiddle(两个输入):< a href =http://jsfiddle.net/fDbJt/> http://jsfiddle.net/fDbJt/

解决方案 div>

不幸的是,它只是一个默认的输入提交表单,只有一个输入。



你可以给每个人一个javascript命令提交表单,或者放置宽度为0和/或可见性:无的提交按钮。
例如:

 < form> 
< input style ='width:0; visibility:hidden'type ='submit'>
<输入>
<输入>
< / form>


Can anyone explain this behavior? Pressing the Enter key in an HTML form's text box submits the form when the form contains a single text box, but not when the form contains two or more text boxes.

jsFiddle (one input): http://jsfiddle.net/gpPTa/
jsFiddle (two inputs): http://jsfiddle.net/fDbJt/

解决方案

Unfortunately it's a default for the form to submit on enter with only one input.

You can either give each of them an javascript command that submits the form, or place a submit button with width: 0 and/or visibility: none. For example:

<form>
    <input style='width:0; visibility:hidden' type='submit'>
    <input>
    <input>
</form>

这篇关于按Enter键提交一个输入的HTML表单,但不是两个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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