gpt4 book ai didi

javascript - 定位 anchor 标记后页面跳转回顶部

转载 作者:行者123 更新时间:2023-11-28 00:24:04 24 4
gpt4 key购买 nike

大家好,我使用 WordPress,当用户单击链接时我需要跳转到评论。single.php 在新选项卡中打开,并在 anchor (comment-id)上加载页面,但之后它总是跳回页面顶部。

我知道这是 javascript 的问题(因为当我禁用 js 时它工作得很好),但我不确定在哪里可以找到 javascript 的平静,我必须停止或更改 single.php。有谁知道如何以及在哪里更改 javascript。这样我就可以在点击不同页面上的链接后留在评论中?

这是目标<a name="comment'.$comment_ID.'" href="#comment'.$comment_ID.'" onclick="deletco('.$comment_ID.')">DELETE</a>

这是从其他页面到 single.php 上的目标的链接

<a href="'.$commpostlink.'#comment-'.$commentid.'" target="_blank">'.$titlecomm.'</a> 

感谢您的帮助

最佳答案

首先,我鼓励您将 JS 文件一一注释掉,它会测试它,告诉您找到负责的 js 文件。

另一种方法是,如果是 javascript 问题,那么您可以使用 jQuery 来做到这一点:

$('a.aCommentLinkCssClass').click(function () {
var url = $(this).attr('href').text();
window.location.href = url;
});

并将 css 类添加到您的链接中:

<a href="'.$commpostlink.'#comment-'.$commentid.'" target="_blank" class="aCommentLinkCssClass">'.$titlecomm.'</a> 

或者如果您只想使用 JavaScript:

<script>
function goToFunction(url) {
window.location.href = url;
}
</script>

在你的html中:

 <?php echo '<a href="'.$commpostlink.'#comment-'.$commentid.'" onclick="goToFunction("'.$commpostlink.'#comment-'.$commentid.'")" target="_blank">'.$titlecomm.'</a>'; ?>

关于javascript - 定位 anchor 标记后页面跳转回顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com