单击锚点链接时,URL不受影响 [英] Keep URL unaffected when anchor link is clicked

查看:125
本文介绍了单击锚点链接时,URL不受影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里检查了其他帖子,没有找到我想要的结果。
我要点击

I've checked other posts on here, no results of what I'm looking for. I want to click on

<a href="#about">About</a>
<div id="about">Content of this..</div>

并使其滚动到该元素,而无需在地址栏中输入www.domain.com/#about

and have it scroll to that element without putting www.domain.com/#about in the address bar

作为一个很好的例子,请查看我在这里,然后单击某些链接-单击它们不会更改地址栏。

As a perfect example please check out this site that I found here and click on some of the links --they don't change the address bar when clicked.

推荐答案

一种可能的解决方法是使用< button> 代替< a>

One possible workaround is to use a <button> instead of a <a>.

所以而不是...。

<a href="#about">About</a>
<div id="about">Content of this..</div>

...您可以将其更改为

...you can change it to

<button href="#about">About</button>
<div id="about">Content of this..</div>

通过这种方式,锚链接不会影响URL。

This way the anchor link will not affect the URL.

这篇关于单击锚点链接时,URL不受影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆