是否有一个下拉菜单作为组件?网上找不到

时间:2019-06-06 18:00:55

标签: javascript html css

我正在尝试创建一个网站,可以通过该网站下载讲道的pdf和mp3文件,但由于无法找到下拉菜单的方法,因此无法执行此操作。

我尝试在引导程序,W3schools等上查找它,但无济于事。

<script>

    function myFunction() {
        document.getElementById("myDropdown").classList.toggle("show");
    }

    window.onclick = function(event) {
        if (!event.target.matches('.dropbtn')) {
            var dropdowns = document.getElementsByClassName("dropdown-content");
            var i;
            for (i = 0; i < dropdowns.length; i++) {
                var openDropdown = dropdowns[i];
                if (openDropdown.classList.contains('show')) {
                    openDropdown.classList.remove('show');
                }
            }
        }
    }
</script>


<li>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson </button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson </button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson 3</button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson 4</button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson 5</button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
    <ul>
        <div class="dropdown">
            <button onclick="myFunction()" class="dropbtn">Lesson 6</button>
            <div id="myDropdown" class="dropdown-content">
                <a href="#" download>Lesson PDF</a>
                <a href="#" download>MP3 File</a>
            </div>
        </div>
    </ul>
</li>

这是我能做的最好的事情,但对我来说还不够。

2 个答案:

答案 0 :(得分:0)

Bootstrap确实具有下拉菜单。

https://getbootstrap.com/docs/4.0/components/dropdowns/

W3Schools(尽管我不会去那里)

https://www.w3schools.com/css/css_dropdowns.asp

答案 1 :(得分:-2)

您可以通过Polymer找到多个组件。 例如:https://www.webcomponents.org/search/dropdown