我在 Firefox 上遇到这个小问题(在 chrome 上工作正常),我有一个按钮列表,这些按钮的 anchor 在页面目标中不同,我使用 id,但是(在 Firefox 上) anchor 仅在第二次单击时起作用,第一次单击仅更改 URL。
<a href="#section1">button 1</a>
<a href="#section2">button 2</a>
目的地
<section id="section1">
some content
</section>
<section id="section2">
some content
</section>
我也已经尝试过 name=""但它仍然需要双击才能工作,有没有方法可以解决这个问题还是 Firefox 上的错误?
最佳答案
试试这个:
<a href="javascript:document.getElementById('section1').scrollIntoView(true);">
Button 1
</a>
<a href="javascript:document.getElementById('section2').scrollIntoView(true);">
Button 2
</a>
目的地:
<section id="section1">
some content
</section>
<section id="section2">
some content
</section>
关于html - 需要在 html anchor 上单击两次才能转到 id 或名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67134323/