html - 需要在 html anchor 上单击两次才能转到 id 或名称

标签 html vue.js firefox anchor

我在 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/

相关文章:

unit-testing - 使用 Vue.js 和 Jest 进行 URL 重定向测试

javascript - 在所有脚本完全加载之前如何防止单击图像

html - WordPress header 丢失

vue.js - Nuxt基于域名的动态布局?

node.js - docker ,NodeJs,Vuejs : can't access with localhost

Javascript 代码在 IE 中工作但在 Firefox 中不起作用?

javascript - 字段焦点在 Firefox 中不起作用,setTimeout(function(){id.focus();},0);

Java Selenium Firefox 驱动程序 - 文本框 Onchange 问题

javascript - Jquery 水印插件在 IE9 中将水印作为表单的值提交

javascript - 我如何使用 javascript 和 css 使栏出现和消失