远程服务器上的空 href 标记 returns 当前 url

Empty href tag returns current url on remote server

我留下了几个没有值的 href 标签。但是,在将应用程序部署到远程服务器后,这些标签会填充 url 对应于该服务器上的应用程序位置。

因此,如果我的应用程序位于 http://www.foo.org/href = "" 将替换为 href = "http://www.foo.org/"

为什么?

空假设 href="#"

尝试使用

<a href="javascript:void(0);">click</a>

<a href="" onclick="event.preventDefault();">click</a>

这是设计使然。

根据RFC 2396

A URI reference that does not contain a URI is a reference to the current document. In other words, an empty URI reference within a document is interpreted as a reference to the start of that document, and a reference containing only a fragment identifier is a reference to the identified fragment of that document. Traversal of such a reference should not result in an additional retrieval action. However, if the URI reference occurs in a context that is always intended to result in a new request, as in the case of HTML's FORM element, then an empty URI reference represents the base URI of the current document and should be replaced by that URI when transformed into a request.