加载页面时隐藏div,并在单击链接时显示(Hide div when the page is loaded and show when link is clicked)

系统教程 行业动态 更新时间:2024-06-14 16:59:47
加载页面时隐藏div,并在单击链接时显示(Hide div when the page is loaded and show when link is clicked)

我把这个简单的代码用于下拉菜单,它到目前为止工作。 问题是当我加载页面时,会显示#drop菜单,这显然不是我们想要的。 目标是在单击#submenu链接时显示#drop菜单,而不是立即显示.drop菜单。

我在下面修改了我的代码,因为我需要一个div元素,而不是一个列表。

JS

$(document).ready( function(){ $('#submenu').click( function(event){ event.stopPropagation(); $('#drop').toggle(); }); $(document).click( function(){ $('#drop').hide(); }); });

HTML

<a href="#" id = "submenu">Products</a> <div id = "drop" > DROP DOWN MENU </div>

I took this simple code for drop down menu and it's working so far. The problem is that when I load the page, #drop menu is displayed, which is obviously not what we want. The goal is to show the #drop menu when #submenu link is clicked, not immediately.

I modified my code below, because I need a div element, not a list.

js

$(document).ready( function(){ $('#submenu').click( function(event){ event.stopPropagation(); $('#drop').toggle(); }); $(document).click( function(){ $('#drop').hide(); }); });

html

<a href="#" id = "submenu">Products</a> <div id = "drop" > DROP DOWN MENU </div>

最满意答案

添加一些CSS:

#drop { display: none; }

Add some css:

#drop { display: none; }

更多推荐

本文发布于:2023-04-17 09:08:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/8db2502da689739340b624b22b984021.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并在   单击   加载   页面   链接

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!