gpt4 book ai didi

javascript - Accordion 菜单展开 - 菜单更改

转载 作者:行者123 更新时间:2023-12-01 01:47:53 25 4
gpt4 key购买 nike

在垂直 Accordion 菜单中,我想用其他菜单或分区替换菜单内容。这是我的代码

<nav>
<ul id="nav">
<li><a href="#">Menu 1</a>
<div> New Menu 1</div>
<ul>
After clicking on each header we will show/hide the internal navigation links. This situation can get tricky when trying to implement sub-navigation and sub-sub-navigation if you want to show/hide those as well. A better solution is to nest a third element which is also displayed immediately with all the other links, but rendered using additional padding.


</ul>
</li>
<li><a href="#">Menu 2</a>
<div> New Menu 2</div>
<ul>
Create html drop down menus for web page navigation in a few clicks! Define text, font, color, URL and more for the multilevel dropdown menus. You don't need to write any code by yourself. Horizontal drop down menus builder will generate it for you. You can preview menus in web browser without quitting the program. Css drop down menus render perfectly in Firefox, Safari and Chrome. Html drop down menus also works on non-CSS3 compitable browsers
</ul>
</li>
<li><a href="#">Menu 3</a>
<div> New Menu 3</div>
<ul>
PURE CSS Menu Maker is a free and powerful graphical user interface for creating 100% pure CSS web menus. CSS menus do not require JavaScript or plug-ins in order to run. PURE CSS Menu Maker can create horizontal as well as vertical menus. Menus generated with PURE CSS Menu Maker may be modified freely, either with PURE CSS Menu Maker or by hand.
</ul>
</li>

</ul>
</nav>

脚本

 $(document).ready(function()
{
$('#nav > li > ul:eq(0)').show();
$("#nav > li > a").on("click", function(e)
{
if($(this).parent().has("ul"))
{

e.preventDefault();
}

if(!$(this).hasClass("open"))
{
// hide any open menus and remove all other classes
$("#nav li ul").slideUp(350);

$("#nav li a").removeClass("open");


// open our new menu and add the open class
$(this).next("ul").slideDown(350);

$(this).addClass("open");

}

else if($(this).hasClass("open")) {
$(this).removeClass("open");
$(this).next("ul").slideUp(350);
}
});
});

单击时我想用 div 更改菜单并在下一个菜单单击时隐藏该 div。怎样才能做到呢?谢谢。

这是一个 fiddle : http://jsfiddle.net/sW96K/

最佳答案

您可以尝试使用简单的slideToggle()

           $(document).ready(function()
{
$('#nav > li > ul:eq(0)').show();
$("#nav li a").on("click", function(e)
{
$(this).siblings("ul").slideToggle(350);
});
});

检查这个 fiddle :http://jsfiddle.net/Kritika/ZXE6K/

此代码将在单击时打开一个菜单,但不会关闭其他打开的菜单。这是简单的隐藏/显示
分区

关于javascript - Accordion 菜单展开 - 菜单更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17544688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com