使用 tabindex 和 jquery 绑定焦点事件而不是触发任何你想要的
$("li a").focus(function() {
$(this).parent().find('ul').slideDown(200); // example of targeting nested UL with slide down animation
});
它应该像这样工作,然后使用模糊事件隐藏该子菜单
$("li a").blur(function() {
// your code here to hide submenu
});
启用点击事件:
$("li a").click(function() {
// target all opened submenus and hide them by its class name
$("ul.active-submenu").slideUp(200).removeClass("active-submenu");
// adds class to submenu so you can determine easily which is active
$(this).parent().find('ul').slideToggle(200).toggleClass('active-submenu');
});