我如何使用“输入”正确的表单提交 [英] How do I use "enter" correctly for form submission

查看:71
本文介绍了我如何使用“输入”正确的表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我从未真正掌握过这个:



我有一个页面用户可以在其中添加详细信息,但登录控件始终位于左上角。



在任何专业网站上,我都可以输入我的登录详细信息并点击输入,但如果我没有,那么输入将提交我填写的内容。



这是怎么做到的?专业网站如何管理这个?当我点击进入时,它是基于哪个控件处于活动状态(聚焦)?



谢谢^ _ ^

Andy

Hi,

I never really got the hang of this:

I have a page where the user could add details, but the login control is always there in the top left.

On any professional site, I can enter my login details and hit "enter", but if I don't then "enter" will submit the for I filled out.

How is this done? How do pro sites manage this? Is it based on which control is active (focused) when I hit enter?

Thanks ^_^
Andy

推荐答案

当您在表单上按Enter时,浏览器将单击表单上的第一个按钮,如果这是您的提交/登录按钮,那么人们可以输入他们的详细信息只需按Enter键即可登录。



如果您想要一个登录表单,例如,在同一页面上有一个搜索表单,那么您有两个表单。一个用于登录,一个用于搜索。这样按Enter键只会触发用户所在的那个。



如果这是WebForms并且整个页面都包含在一个服务器表单中(带有runat的表单标签) =服务器)然后所有控件都在一个表单中,因此如果您的登录区域有一个登录按钮而您的搜索区域是一个搜索按钮,那么在搜索区域中单击Enter将点击登录按钮,因为它是您单个表单中的第一个按钮。为了解决这个问题,你可以在asp:Panel中包装你的逻辑表单,并指定面板上的默认按钮属性。这样做是因为asp.net将javascript添加到挂钩到按键事件的页面中,当您按Enter键时,它将单击外部面板的默认按钮属性中指定的按钮。这样,当您单击在登录中输入时,将触发登录按钮单击事件,当您在搜索中执行此操作时,将触发搜索按钮的单击事件。
When you press "Enter" on a form the browser will "click" the first button on the form, so if that is your Submit/Login button then people can enter their details and just press enter to login.

If you want a login form and, for example, a search form on the same page then you have two forms. One for login and one for search. That way pressing enter will only trigger the one the user is on.

If this is WebForms and your entire page is wrapped in a single server form (form tag with runat=server) then all your controls are in one form so if your login area has a login button and your search area a search button then clicking enter in the search area will click the login button as it is the first button in your single form. To get around this you wrap your "logical" forms in an asp:Panel and specifiy the default button property on the panel. What this does is cause asp.net to add javascript to your page that hooks into the keypress events and when you press enter it will click the button specified in the default button property of the outer panel. This way when you click enter in login the login button click event is triggered, and when you do it in search the click event of the search button is triggered.


这篇关于我如何使用“输入”正确的表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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