简体   繁体   English

jQuery slidetoggle不适用于div,ul和display:无

[英]jquery slidetoggle not working with div, ul, and display: none

I'm trying to toggle a menu dropdown with slideToggle but I can't seem to get it working. 我正在尝试使用slideToggle切换菜单下拉菜单,但似乎无法正常工作。 My goal is to click on "Attack" and have the list of attack options show. 我的目标是单击“攻击”并显示攻击选项列表。 Here is my code. 这是我的代码。

<div class="turn-option" id="attack">
    <h2>Attack</h2>
    <div class="attack-menu">
        <ul>
            <li class="attack-type">Attack 1</li>
            <li class="attack-type">Attack 2</li>
            <li class="attack-type">Attack 3</li>
            <li class="attack-type">Attack 4</li>
        </ul>
    </div>
</div>


.attack-menu {
    display: none;
}

$(document).ready(function() {
    $("#attack").click(function() {
        $(".attack-menu").slideToggle("fast");
    });
});

This works fine. 这很好。 Your jquery library might be causing the error. 您的jquery库可能导致错误。 Try including this script : 尝试包括以下脚本:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

Refer this link : Example 参考此链接: 示例

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

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