简体   繁体   English

使用 javascript 或 jquery 在 html 和 css 中制作下拉菜单

[英]Making dropdown menu in html & css with javascript or jquery

这是我在<li class="drop-down"><a href="#"></a></li>然后我在页面中的位置在底部,然后当我单击它时 -> drop-向下 <- 然后我的页面在顶部,我该如何解决这个问题,我的导航栏是固定位置。

It is the normal behaviour of any browser, that it will navigate to the top of your page if you click on an anchor that's href ttirbute is a hash "#".这是任何浏览器的正常行为,如果您单击 href ttirbute 是哈希“#”的锚点,它将导航到您的页面顶部。 If you want to prevent this behaviour, please leve the hash away, or prevent it by using Javascript.如果您想阻止这种行为,请将散列放在一边,或通过使用 Javascript 来阻止它。

href="#"

casuses that issue for you.为您解决这个问题。 Try linking it to an actual item in your page.尝试将其链接到页面中的实际项目。 Or what you could do:或者你可以做什么:

href="#!"

or a third option:或第三种选择:

href="#" class="stop"

with jQuery使用 jQuery

$('.stop').click(function(e) {
    e.preventDefault();
});

You can use the following without JavaScript您可以在没有 JavaScript 的情况下使用以下内容

<a href="javascript:;>My link</a>

Or或者

<a href="javascript:void(0);">My link</a>

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

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