开发者

Window scrolling down when there are anchor links

开发者 https://www.devze.com 2023-02-25 03:49 出处:网络
I have got an issue with anchors links / deep linking. I have got few tabs in a page with ids such as tab1, tab2. When I hit the URL with anchor = \"#tab2\" I can select the right tab through JavaScri

I have got an issue with anchors links / deep linking. I have got few tabs in a page with ids such as tab1, tab2. When I hit the URL with anchor = "#tab2" I can select the right tab through JavaScript but the window scrolls down.

I tried to change the window.location.hash on-the-fly and delete the id name but still the page is scrolled down. I even tried to invoke $(window).scrollTop(0) fu开发者_如何学Cnction but it doesn't work.

Any help on it?


Well, seems like you want to do only your function in javascript and not go to link. Then add return false; to your function.

function test()
{
  alert('clicked');
  return false;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消