简体   繁体   English

禁用锚跳

[英]disable anchor jump

i'm working on an interactive map by Winston Wolf. 我在Winston Wolf的互动地图上工作。 I have a world map with each continent clickable and displaying countries in that continent. 我有一张世界地图,每个大陆都可以点击并显示该大陆的国家。 When i click on a continent eg Africa the page jumps to the countries of Africa(as you would expect). 当我点击非洲大陆时,页面会跳到非洲国家(如您所料)。 My question is, can i stop it jumping. 我的问题是,我可以阻止它跳跃。 This is because the list of countries is directly under the map therefore hiding the map(due to the page jumping to the anchor id) when you click on a continent. 这是因为当您单击大陆时,国家/地区列表直接位于地图下,因此会隐藏地图(由于页面跳转到锚点ID)。 My code is as follows: 我的代码如下:

<ul id="continents">
<li id="c1"><a href="#africa">Africa</a></li>
</ul>

<ul id="africa">
<a href="countrymapiframe.asp" target="_self" title=""><li>Egypt</li></a>
    <!--more countries-->
</ul>

i tried onclick="return false", with no luck, any help would be greatly appreciated. 我试过onclick =“返回假”,没有运气,任何帮助将不胜感激。

Yes you can with javascript. 是的你可以用javascript。 A simplified way of doing it is adding a return false; 一种简化的方法是添加一个return false; onclick event to the anchor onclick事件到锚点

<a href="countrymapiframe.asp" target="_self" title="" onclick="return false;">

but it's generally better to not use the inline onclick attribute. 但通常最好不要使用内联onclick属性。 I suggest looping through the anchors with javascript and assigning a listener in that loop. 我建议用javascript循环遍历锚点并在该循环中分配一个监听器。

您可以尝试此代码

<a href="javascript:void(0);" target="_self"> Test </a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM