锚标记中hash(#)后面的文件夹是什么意思

What is the meaning of folder after hash(#) in the anchor tag?

本文关键字:文件夹 意思 是什么 hash      更新时间:2023-09-26

在本角度教程的组件模板部分,他们使用以下代码:

...
<ul class="phones">
  <li ng-repeat="phone in $ctrl.phones | filter:$ctrl.query | orderBy:$ctrl.orderProp" class="thumbnail">
    <a href="#/phones/{{phone.id}}" class="thumb">
      <img ng-src="{{phone.imageUrl}}" alt="{{phone.name}}" />
    </a>
    <a href="#/phones/{{phone.id}}">{{phone.name}}</a>
    <p>{{phone.snippet}}</p>
  </li>
</ul>
...

在锚点标记中,他们使用以下值作为href "#/phones/{{phone.id}}"。据我所知,href="#"一点击就会跳到页面顶部。并且href="#mydiv"将跳转到id为mydiv的元素。

我从未见过像href="#/folder1/myimg.jpg"这样的东西。它等同于href="/folder1/myimg.jpg"吗?

将"#"符号作为某个内容的href意味着它不指向不同的URL,而是指向同一页面上的另一个id或name标记。例如:

<a href="#bottomOfPage">Click to go to the bottom of the page</a>
blah blah
blah blah
...
<a id="bottomOfPage"></a>

然而,如果没有id或名称,则它将变为"无位置"

有关更多信息,您可以查看。。。什么是href="为什么要使用它?

但在angularJS中,它用于路由请求。。。由于angularJS为构建的Single Page Application提供了非常好的支持。。#之后的参数用于查找要呈现的正确页面。。。。

这里有一个很好的例子。。但你需要时间来深入了解它。。

似乎所有锚事件都会被javascript中断,也许页面会使用ajax在后台加载,浏览器的地址行会更改,但不会导致浏览器重新加载页面。在HTML4中,它无法在不重新加载页面的情况下更改地址行。所以这是一种变通方法:

  1. 指定js应该加载哪个页面
  2. 让用户能够在将来引用或共享特定页面