使用 javascript 自动提交表单是不好的做法吗?
我的开发部门正在争论如何在填写所有元素后使用 javascript 自动提交表单。我们有一个包含 2 个选择元素的表单,我们当前提交的两个元素都已被选中。
使用 javascript 自动提交表单有哪些好的优点和缺点?到目前为止,我们提出的唯一真正的论点是,如果自动提交表单,用户将无法轻松地更正其选择:他必须返回到表单所在的上一页。但是,如果用户正确填写了表单,可能会节省他一些时间(也许半秒,但仍然如此)。
My development department is in an argument about autosubmitting a form with javascript when all elements are filled in. We've got a form with 2 select-elements, which we currently submit is both are selected.
What are some good pro and con arguments for autosubmitting a form with javascript? The only real argument we've came up with so far is that the user can't easily correct it's selection if the form is autosubmitted: he'll have to go back to the previous page where the form is located. However, if the user does fill in the form correctly, it might save him some time (half a second maybe, but still).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是意想不到的行为。选择(除了令人困惑的例外)不提交表格。单击提交按钮提交表单。
It is unexpected behaviour. Selections (confusing exceptions aside) do not submit forms. Clicking a submit button submits forms.
当您将结果动态加载到当前页面时,自动提交效果很好,但您仍然不应该依赖于此。关于你的情况——绝对不是。
Autosubmiting plays well when you load results dynamically into the current page, but still you should not rely on this. About your case - definitely no.
要“修复”您提到的论点(这确实是一个很好的论点),您可以在自动提交之前添加确认对话框:
除此之外,我认为自动提交没有任何问题。
To "fix" the argument you mentioned (which is indeed good one) you can add
confirm
dialog before auto submitting:Apart of that, nothing wrong in my opinion in auto submitting.