真的需要对表格采取行动吗? [英] Is action really required on forms?

查看:32
本文介绍了真的需要对表格采取行动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里说它是必需的

http://www.w3schools.com/tags/att_form_action.asp

但是我看到即使我没有指定 action 属性也会提交表单,并且表单被提交到当前页面,这正是我想要的.

but I see that forms get submitted even if I don't specify an action attribute, and the form gets submitted to the current page which is exactly what I want.

推荐答案

要求仅通过标准.完全有可能在页面上做任何您想做的事情而不遵循标准.如果您这样做,事情可能无法正常显示或工作,但很可能会.目标是关注他们,如果你关注他们,你的页面将永远工作;您不必担心任何事情.

The requirement is only by standards. It is perfectly possible to do whatever you want on a page and not follow standards. Things may not display or work correctly if you do that, but likely they will. The goal is to follow them, and the idea is that if you follow them, your page will always work; you don't have to worry about anything.

是的,该表单要求在 HTML4 中具有 action 属性.如果未设置,浏览器可能会使用与向其提供空字符串相同的方法.你真的应该设置 action="",它是完全有效的 HTML4,遵循标准,并达到完全相同的结果.

Yes, the form is required to have an action attribute in HTML4. If it's not set, the browser will likely use the same method as providing an empty string to it. You really should set action="" which is perfectly valid HTML4, follows standards, and achieves the same exact result.

在 HTML5 中,您实际上可以在提交按钮本身上指定操作.如果没有,则使用表单的操作,如果未设置,则默认为空字符串(请注意,您不能在 HTML5 中将操作显式设置为空字符串).

In HTML5, you can actually specify an action on the submit button itself. If there isn't one, it uses the form's action and if that is not set, it defaults to the empty string (note you cannot explicitly set the action to an empty string in HTML5).

这篇关于真的需要对表格采取行动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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