我正在尝试使用 JQuery 切换创建一个滑动子菜单。我尝试了以下但无济于事:
<script>
$(".menu li a").click(function(){
var ul = $(this).children("ul");
if (ul.is(":none")) {
ul.slideDown();
} else {
ul.slideUp();
}
});
</script>
并且
<script>
$("ul li.menu-item a").click(function() {
$(this).children("ul").toggle();
});
</script>
它适用的 HTML 代码是:
<div class="menu-brk-products-container">
<ul id="menu-brk-products" class="menu">
<li id="menu-item-65" class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-65"><a>Smoke Alarms – Ionisation</a>
<ul class="sub-menu">
<li id="menu-item-432" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-432"><a href="/?portfolio_cats=battery-powered-smoke-alarms">Battery Powered Alarms</a>
</li>
</ul>
</li>