Javascript:我的Javascript代码不工作?

javascript : my javascript code not working ??

本文关键字:Javascript 工作 代码 我的      更新时间:2023-09-26

似乎一切都很好,但当我点击按钮时,我的下拉菜单不出现,我认为原因是javascript不工作!!样式文件在我的CSS文件夹,它的工作很好这是我的代码。

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/skin.css"/>
        <title>Change Directory Content</title>
        <script>
            /* When the user clicks on the button,
             toggle between hiding and showing the dropdown content */
            function myFunction() {
                document.getElementById("myDropdown").classList.toggle("show");
            }
        </script>
    </head>
    <body>
        <%@include file="header.jsp" %>
        <div id="wrapper">
            <div id ="page">
                <div id="content">                    
                    <div class="box">
                        <div class="dropdown">
                            <button onclick="myFunction()" class="dropbtn">Dropdown</button>
                            <div id="myDropdown" class="dropdown-content">
                                <a href="#home">Home</a>
                                <a href="#about">About</a>
                                <a href="#contact">Contact</a>
                            </div>
                        </div>
                        <!--End Div -->
                        <div class="dropdownL">
                            <button onclick="myFunction()" class="dropbtn">Dropdown</button>
                            <div id="myDropdown" class="dropdown-content">
                                <a href="#">Link 1</a>
                                <a href="#">Link 2</a>
                                <a href="#">Link 3</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <br class="clearfix"/>
        </div>
        <%@include file="footer.jsp" %>
    </body>
</html>

有什么帮助吗?

如果你想使用jquery
在这里输入链接描述

<script>
        /* When the user clicks on the button,
         toggle between hiding and showing the dropdown content */
        function myFunction(id) {
            $(id).siblings(".dropdown-content").toggle('slow');
        }
</script>

用下拉