html 中 a 标签中 href 的路径相关问题

一、普通情况

假设浏览器目前指向 http://foo/bar/baz.html 这个地址,那么:

  • <a href="reset/index.html"> 代表的链接是 http://foo/bar/reset/index.html.
  • <a href="/reset/index.html"> 代表的链接是 http://foo/reset/index.html.

二、有 BASE 的情况

下面这个链接将指向 http://example.com/foobar/reset/index.html ,不管当前是在哪里。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
 <HEAD>
   <TITLE>Base element example</TITLE>
   <BASE href="http://example.com/foobar/">
 </HEAD>

 <BODY>
   <P><a href="reset/index.html">Reset CSS</a>
 </BODY>
</HTML>

参见:https://stackoverflow.com/questions/10659459/starting-with-a-forward-slash-in-html-for-href

原文地址:https://www.cnblogs.com/fanlumaster/p/14399227.html