Safari:禁用表单提交输入? [英] Safari: Disable form-submit on Enter?

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

问题描述

以下问题:

在我的网站上,我有两种形式。一个用于登录,一个用于主数据。
我在mainform中只有一个提交按钮。
loginform是通过js在mainform提交中提交的。



这可以正常工作。但在Safari中,我可以按Enter键,而我的焦点在登录表单内。这会发送没有mainform的登录表单,所以我得到一个错误(它将我重定向到我提交的json请求的普通视图)。



是否有可能禁用on enter pressed按钮?

解决方案

如果你说你使用JS来提交表单中的数据为什么不用< form onsubmit =return false;> 取消浏览器的默认行为。这样,无论您按下提交按钮还是按回车键,它都不会被发送。 onsubmit =return false不应该干扰从JS调用表单上的submit()方法。


Following problem:

On my site, I have two forms. One for login and one for main data. I have only one submit button in the mainform. The loginform is submitted via js on mainform submit.

This works fine. But in Safari I can press Enter while my focus is inside the login form. This will send the login form without the mainform, so I get an error (It redirects me to a plain view of a json I request on submit).

Is it possible to disable the "on enter pressed" action?

解决方案

If you say you use anyway the JS to submit the data in the form why not cancel the default behaviour of the browser with <form onsubmit="return false;">. This way no matter if you press the submit button or press enter in an input it won't be sent. The onsubmit="return false" shouldn't interfere with calling the submit() method on the form from JS.

这篇关于Safari:禁用表单提交输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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