
如何不使用 标签实现在页面中跳转位置?
问题描述:
页面代码中存在 .item 元素,需要通过为其增加 href 属性来实现跳转位置。
解答:
JavaScript 解决方案:
代码示例:
<script>
function test(href) {
const id = href.replace('#', '');
document.getElementById(id).scrollIntoView();
}
let liEle = '';
for (data of partDynamicDataTraverse.list) {
liEle += `<li onclick="test('${data.href}')"><div class="item">${data.name}</div></li>`;
}
partDynamicDataTraverse.$element.append(liEle);
</script>最终效果:
点击 .item 元素后,页面滚动到相应目标位置。
以上就是如何不使用 a 标签实现页面内跳转?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号