【问题标题】:HTML href tag adding a '#!' to fragment添加“#!”的 HTML href 标签碎片化
【发布时间】:2017-12-01 08:39:16
【问题描述】:

我希望通过在 HTML 中使用锚标记来重定向到我的页面的某个片段。

到目前为止,我已经

<ul>
    <li><a href="#Links">Links</a></li>
</ul>

作为链接,然后在代码中

<section id = "Links">
    ...
</section>

但是,当我在本地主机上进行测试时单击锚点时,URL 变为

http://localhost:5000/#!#Links

而不是

http://localhost:5000/#Links

这是为什么?单击链接后,如何消除 URL 中的 shebang?

另外,我的 webapp 正在使用 AngularJS。我不知道这是否相关。

【问题讨论】:

    标签: html angularjs web hyperlink


    【解决方案1】:

    使用

    <a href="#Links">
      <section ..>
        ...
      </section>
    </a>
    
    <ul>
        <li><a href="http://localhost:5000/#Links">Links</a></li> 
    </ul>
    

    【讨论】:

    • 这仍然有同样的问题,如果我想从 localhost 迁移则不起作用
    【解决方案2】:

    已解决。这是因为我使用的是 angularJS。相反,我做了

    <ul>
        <li><a href="#Links" target="_self">Links</a></li>
    </ul>
    
    <section id = "Links" target="_self">
        ...
    </section>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-16
      • 2012-03-04
      • 2018-02-02
      • 1970-01-01
      • 2011-04-26
      相关资源
      最近更新 更多