我正在试图弄清楚我需要为以下函数编写的jQuery。当有人点击跨度'展开'时,我希望我可以显示包含点击范围的LI的子菜单(UL)。
默认情况下,通过CSS隐藏子UL ..但是当点击展开时,我想显示它。
例如,请参阅下面的代码......
<li id="menu-item-15031" class="menu-item menu-item-type-post_type menu-item-object-page current-page-ancestor current-menu-ancestor current-page-parent current_page_ancestor menu-item-15031"><a href="http://www.tintworld.com/automotive-services/">Automotive Services</a>
<ul class="sub-menu">
<li id="menu-item-15039" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor menu-item-15039"><a href="http://www.tintworld.com/automotive-services/window-tinting/">Window Tinting</a>
<ul class="sub-menu">
<li id="menu-item-15033" class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-484 current_page_item menu-item-15033"><a href="http://www.tintworld.com/automotive-services/car-window-tinting/">Car Window Tinting</a></li>
<li id="menu-item-15040" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15040"><a href="http://www.tintworld.com/automotive-services/computer-cut-film-system/">Computer Cut Window Tint System</a></li>
<li id="menu-item-15041" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15041"><a href="http://www.tintworld.com/automotive-services/solar-window-tint/">Solar Window Tint</a></li>
<li id="menu-item-15042" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15042"><a href="http://www.tintworld.com/automotive-services/custom-tint-designs/">Custom Tint Designs</a></li>
<li id="menu-item-15043" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15043"><a href="http://www.tintworld.com/automotive-services/removing-window-tint/">Removing Window Tint</a></li>
<li id="menu-item-15044" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-15044"><a href="http://www.tintworld.com/automotive-services/window-tint-regulations/">Window Tint Regulations</a></li>
</ul>
</li>
</ul>
<span class="arrow"></span>
</li>
我知道jQuery非常容易,但说实话,我已经筋疲力尽了,现在无法解决它。
请帮帮我。 :)
答案 0 :(得分:2)
尝试其中任何一项。请你好好休息吧:)
$(".arrow").click( function () {
$(this).closest("li").find("ul.sub-menu").slideToggle("slow");
});
或者
$(".arrow").click( function () {
$(this).prev("ul.sub-menu").slideToggle("slow");
});
或者
$(".arrow").click( function () {
$(this).siblings("ul.sub-menu").slideToggle("slow");
});
答案 1 :(得分:0)
尝试以下代码
$("span").click(function(thisElement)
{
$("#menu-item-15031 > ul").css("display","block");
});
您也可以使用它:
$(".arrow").click( function () {
$(this).closest("li").find("ul.sub-menu").slideToggle("slow");
});