gpt4 book ai didi

javascript - 将按钮链接到另一个页面的一部分

转载 作者:太空宇宙 更新时间:2023-11-04 14:30:47 25 4
gpt4 key购买 nike

我有一个转到另一个页面的链接按钮,它可以工作,但我希望链接转到该页面的特定部分。我知道我应该为此使用 jquery,并且出于某种原因它没有跳转到我希望它跳转到的部分。

我的按钮链接:

 <div class="btn_holder top-slide"><a 
href="http://testurl.com/media#isabelo"><p class="leeu_button">READ
MORE</p></a>
</div>

我目前滚动到页面底部而不是 id="isabelo"的部分。所以这个 jquery 有效,但它不是我想要的。希望你明白。

$(document).ready(function(){ 

//check if hash tag exists in the URL
if(window.location.hash) {
$("html, body").animate({ scrollTop: $(document).height() }, 1000);
1000);
} });

我也已经尝试过这个(根本不起作用):

$(document).ready(function(){ 

//check if hash tag exists in the URL
if(window.location.hash) {
$('html, body').animate({ scrollTop: $("#isabelo").offset().top }, 1000);
}
});

我试图链接到的页面有一个 id="isabelo"的 div

<div class="content_holder terms_row" id="isabelo">

最佳答案

<a href="http://www.example.com/some-page-or-other.html#exactline">Click here</a>

你想跳转到的位置应该有name="exactline"属性

关于javascript - 将按钮链接到另一个页面的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37049868/

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