简体   繁体   English

链接无法在JavaScript下拉菜单中使用

[英]Links not working in JavaScript drop down menu

I am a beginner to JavaScript and can't figure out how to get links working within this dd menu. 我是JavaScript的初学者,无法弄清楚如何在此dd菜单中获取链接。 I'm assuming it has something to do with the javascript function closing the dropdown menu wherever you click overriding the links. 我假设它与关闭下拉菜单的javascript函数有关,只要你点击覆盖链接。

HTML HTML

<div id="right_box">
    <div id="wrap">
        <div id="dropdown" class="ddmenu"> User Settings 
            <ul> 
                <li><a href="#">Settings</a></li>
                <li><a href="logout.php">Log Out</a></li>
            </ul> 
        </div> 
    </div>  

JavaScript JavaScript的

<script type="text/javascript">
     $("#dropdown").on("click", function(e){
        e.preventDefault();

        if($(this).hasClass("open")) {
            $(this).removeClass("open");
            $(this).children("ul").slideUp("fast");
        } else {
            $(this).addClass("open");
            $(this).children("ul").slideDown("fast");
        }
    });
</script>

It happens because you're using e.preventDefault() , remove it. 这是因为你正在使用e.preventDefault() ,删除它。
When you use it you stop the default a action. 当你使用它,你停止默认的a动作。

demo 演示

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

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