action attribute is required 但你可以指定一个空的 URI 引用来引用当前的 URI:
<form method="POST" action="">
编辑 好的,这实际上是 WebKit 528+(请参阅 Bug 19884)的一个已提交错误,当空 URI 与使用 BASE 元素的指定基本 URI 一起使用时。在这种情况下,WebKit 采用基本 URI,而不是从基本 URI 解析空 URI。
但这是correct behavior according to RFC 3986:
5.1。建立基础 URI
术语“相对”意味着存在一个“基本 URI”
应用相对参考。 […]
引用的基本 URI 可以通过以下四种方式之一建立,
下面按优先顺序讨论。优先顺序可以
可以根据层来考虑,其中最里面定义的基础
URI 具有最高优先级。这可以以图形方式可视化
如下:
.----------------------------------------------------------.
| .----------------------------------------------------. |
| | .----------------------------------------------. | |
| | | .----------------------------------------. | | |
| | | | .----------------------------------. | | | |
| | | | | <relative-reference> | | | | |
| | | | `----------------------------------' | | | |
| | | | (5.1.1) Base URI embedded in content | | | |
| | | `----------------------------------------' | | |
| | | (5.1.2) Base URI of the encapsulating entity | | |
| | | (message, representation, or none) | | |
| | `----------------------------------------------' | |
| | (5.1.3) URI used to retrieve the entity | |
| `----------------------------------------------------' |
| (5.1.4) Default Base URI (application-dependent) |
`----------------------------------------------------------'
在这种情况下,带有href 属性的BASE 元素是嵌入在内容中的基本URI。并且 嵌入在内容中的基本 URI 比用于检索实体的 URI 具有更高的优先级。所以 WebKit 的行为实际上是根据 RFC 3986 的预期行为。
但in HTML 5 this behavior of an empty URI in form’s action(仍是草案)与 RFC 3986 不同:
如果 action 是空字符串,则让 action 为 document's address。
注意:此步骤是 RFC 3986 的 willful violation,需要在此处处理基本 URL。这种违规的动机是希望与遗留内容兼容。 [RFC3986]
坦率地说,源代码中此注释之后的 HTML 注释如下:
<!-- Don't ask me why. But that's what IE does. It even treats
action="" differently from action=" " or action="#" (the latter
two resolve to the base URL, the first one resolves to the doc
URL). And other browsers concur. It is even required, see e.g.
http://bugs.webkit.org/show_bug.cgi?id=7763
https://bugzilla.mozilla.org/show_bug.cgi?id=297761
-->
所以这是一个源自 Internet Explorer 的错误,后来成为事实上的标准。