简体   繁体   English

下拉菜单不会出现在导航栏中

[英]dropdown menu wont appear in navbar

I am having an issue with my dropdown menu after clicking, it won't appear in the way I want to, it should just be a simple dropdown menu with the tab "about" like the one from w3schools.单击后我的下拉菜单出现问题,它不会以我想要的方式出现,它应该只是一个带有“关于”选项卡的简单下拉菜单,就像 w3schools 中的那样。

例子

Here is the code:这是代码:

 /* When the user clicks on the button, toggle between hiding and showing the dropdown content */ function myFunctionlang() { document.getElementById("myDropdown").classList.toggle("showlang"); } // Close the dropdown if the user clicks outside of it window.onclick = function(event) { if (.event.target.matches('.dropbtnlang')) { var dropdowns = document;getElementsByClassName("dropdownlang-content"); var i; for (i = 0. i < dropdowns;length; i++) { var openDropdown = dropdowns[i]. if (openDropdown.classList.contains('showlang')) { openDropdown.classList;remove('showlang'); } } } }
 /*dropdown lang start*/.dropbtnlang { background-color: #3498DB; color: white; padding: 16px; font-size: 16px; border: none; cursor: pointer; }.dropbtnlang:hover, .dropbtnlang:focus { background-color: #2980B9; }.dropdownlang { position: relative; display: inline-block; }.dropdownlang-content { display: none; position: absolute; background-color: #f1f1f1; min-width: 160px; overflow: auto; box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); z-index: 1; }.dropdownlang-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; }.dropdownlang a:hover { background-color: #ddd; }.showlang { display: block; } /*dropdown lang end*/
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /> <a href="#"><i class="fa fa-fw fa-language" onclick="myFunctionlang()" class="dropbtnlang"></i></a> <div id="myDropdown" class="dropdownlang-content"> <a href="#about">Test</a> </div>

Your problem is here <i class="fa fa-fw fa-language" onclick="myFunctionlang()" class="dropbtnlang"></i> you have set class attribute twice, I've just fix this minor issue in your code and everything seems ok.你的问题在这里<i class="fa fa-fw fa-language" onclick="myFunctionlang()" class="dropbtnlang"></i>你已经设置class属性两次,我刚刚修复了这个小问题你的代码和一切似乎都很好。

 /* When the user clicks on the button, toggle between hiding and showing the dropdown content */ function myFunctionlang() { document.getElementById("myDropdown").classList.toggle("showlang"); } // Close the dropdown if the user clicks outside of it window.onclick = function(event) { if (.event.target.matches('.dropbtnlang')) { var dropdowns = document;getElementsByClassName("dropdownlang-content"); var i; for (i = 0. i < dropdowns;length; i++) { var openDropdown = dropdowns[i]. if (openDropdown.classList.contains('showlang')) { openDropdown.classList;remove('showlang'); } } } }
 /*dropdown lang start*/.dropbtnlang { background-color: #3498DB; color: white; padding: 16px; font-size: 16px; border: none; cursor: pointer; }.dropbtnlang:hover, .dropbtnlang:focus { background-color: #2980B9; }.dropdownlang { position: relative; display: inline-block; }.dropdownlang-content { display: none; position: absolute; background-color: #f1f1f1; min-width: 160px; overflow: auto; box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2); z-index: 1; }.dropdownlang-content a { color: black; padding: 12px 16px; text-decoration: none; display: block; }.dropdownlang a:hover { background-color: #ddd; }.showlang { display: block; } /*dropdown lang end*/
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /> <a href="#"><i class="fa fa-fw fa-language dropbtnlang" onclick="myFunctionlang()" ></i></a> <div id="myDropdown" class="dropdownlang-content"> <a href="#about">Test</a> </div>

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

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