锚标记href没有与div id链接

时间:2022-06-21 20:32:30

I am trying to link an an anchor to a div with in the same page. I did the following:

我试图在同一页面中将一个锚链接到一个div。我做了以下事情:

<a class="chev" href="#yes"> 
       <span class="glyphicon glyphicon-chevron-down"></span>
</a>
...
..
..

<div id="yes"> some content </div>

However, when the link is clicked, the page isn't taking me to the div. Here is the error message I have been getting from the console:

但是,当单击链接时,页面不会将我带到div。这是我从控制台获得的错误消息:

Uncaught Error: [$location:ihshprfx] Invalid url "hostname/#yes", missing hash prefix "#!".

未捕获的错误:[$ location:ihshprfx]无效的网址“hostname /#yes”,缺少哈希前缀“#!”。

I did look at some other solutions, but none of them work.

我确实看过其他一些解决方案,但都没有。

any ideas?

2 个解决方案

#1


1  

I believe the problem is that since you are doing this inside an Angular controller, Angular thinks that the #yes anchor is referring to a specific route, not just a plain old anchor within the page.

我相信问题在于,因为你在Angular控制器中执行此操作,所以Angular认为#yes锚指的是特定路径,而不仅仅是页面中的普通旧锚。

If I remember correctly, specifying target="_self" on the link will tell Angular to just leave it alone and it will just behave like any normal link.

如果我没记错的话,在链接上指定target =“_ self”会告诉Angular只是不管它,它会像任何普通的链接一样。

Try this:

<a class="chev" href="#yes" target="_self"> 
       <span class="glyphicon glyphicon-chevron-down"></span>
</a>
...
..
..

<div id="yes"> some content </div>

More information here: http://eli.eliandlyndi.com/2013/08/26/navigate-urls-angular-application-target_self/

更多信息请访问:http://eli.eliandlyndi.com/2013/08/26/navigate-urls-angular-application-target_self/

#2


-1  

Looks to me like you are doing it backwards. I'm pretty sure that you can only jump to other anchor tags. Try changing the div to an anchor, or put an anchor above it.

在我看来你正在倒退。我很确定你只能跳转到其他锚标签。尝试将div更改为锚点,或在其上方放置锚点。

<a class="chev" href="#yes"> 
   <span class="glyphicon glyphicon-chevron-down"></span>
</a>
...
..
..
<a id='yes'></a>
<div> some content </div>

#1


1  

I believe the problem is that since you are doing this inside an Angular controller, Angular thinks that the #yes anchor is referring to a specific route, not just a plain old anchor within the page.

我相信问题在于,因为你在Angular控制器中执行此操作,所以Angular认为#yes锚指的是特定路径,而不仅仅是页面中的普通旧锚。

If I remember correctly, specifying target="_self" on the link will tell Angular to just leave it alone and it will just behave like any normal link.

如果我没记错的话,在链接上指定target =“_ self”会告诉Angular只是不管它,它会像任何普通的链接一样。

Try this:

<a class="chev" href="#yes" target="_self"> 
       <span class="glyphicon glyphicon-chevron-down"></span>
</a>
...
..
..

<div id="yes"> some content </div>

More information here: http://eli.eliandlyndi.com/2013/08/26/navigate-urls-angular-application-target_self/

更多信息请访问:http://eli.eliandlyndi.com/2013/08/26/navigate-urls-angular-application-target_self/

#2


-1  

Looks to me like you are doing it backwards. I'm pretty sure that you can only jump to other anchor tags. Try changing the div to an anchor, or put an anchor above it.

在我看来你正在倒退。我很确定你只能跳转到其他锚标签。尝试将div更改为锚点,或在其上方放置锚点。

<a class="chev" href="#yes"> 
   <span class="glyphicon glyphicon-chevron-down"></span>
</a>
...
..
..
<a id='yes'></a>
<div> some content </div>