简体   繁体   English

我需要帮助打开菜单点击html中的href链接?

[英]I need help to open menu on click on a href link in html?

i have tried from last few days but unable to open megamenu on click of ahref link, after done some code checkup, i have found some hint in css, in that if i make visibility value to visible then megamenu shows otherwise not, i want that menu to be open only on click right now it's opening on hover event and below code to be executed only onclick of ahref tag我从最近几天开始尝试,但无法在单击 ahref 链接时打开 megamenu,在完成一些代码检查后,我在 css 中找到了一些提示,如果我将可见性值设为可见,那么 megamenu 显示否则不显示,我想要那个菜单现在仅在单击时打开,它在悬停事件时打开,下面的代码仅在 ahref 标记的单击时执行

.menu-subs, .menu-column-4 
{
    visibility: hidden!important;   
}

below is ref.下面是参考。 screenshot for menu菜单截图

menu-screen菜单屏幕

You will need to include some JavaScript to your code.您需要在代码中包含一些 JavaScript。 Here are some examples on how to use it.以下是一些有关如何使用它的示例。

 <button onclick="myFunction()">Click me</button> 
 <element onclick="myScript"> 
 object.onclick = function(){myScript}; 
 object.addEventListener("click", myScript);

I would also recommend using technologies like bootsrap or angular to deal with menus and navigation bars.我还建议使用 bootsrap 或 angular 等技术来处理菜单和导航栏。 They make life easier and is good to know how to use them.它们使生活更轻松,并且很高兴知道如何使用它们。

If you want to make it so that when you click something them menu is visible, you could use the onclick function in the href and toggle the visibility of the menu using css display: non or block.如果您想让它在您单击某些内容时菜单可见,您可以使用 href 中的 onclick 函数并使用 css display: non 或 block 切换菜单的可见性。

HTML: you are creating a div with the css properties of that class and assigning it an id. HTML:您正在使用该类的 css 属性创建一个 div 并为其分配一个 id。 you are also creating a link that will call the javascript function when clicked您还创建了一个链接,单击时将调用 javascript 函数

<div class="menu-subs" id="menu">
// the menu
</div>

<h1 onclick="openMenu()">Open menu</h1>

CSS: the class which is not displayed currently CSS:当前不显示的类

.menu-subs, .menu-column-4 
{
    display: none; 
}

Javascript: Javascript:

function openMneu(){
    //get the menu element in the html
    elem = document.getElementById("menu");

   // set the styling of the menu to visible
   elem.style.display = "block"; //or inline block depending on your other css
}

when openmenu is called by the clicking of the heading open link.当通过单击标题打开链接调用 openmenu 时。 You could also use element.addeventlistender, bit that would be a bit harder, so i suggest you try this.你也可以使用 element.addeventlistender,这会有点困难,所以我建议你试试这个。 This should work, lmk if it does这应该可以,如果可以,请lmk

(this is my second stackoverflow answer :|) (这是我的第二个 stackoverflow 答案:|)

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

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