在模糊时折叠 Bootstrap 导航栏

Collapse Bootstrap navbar on blur

如果用户在菜单中使用 TABBING 并最终跳出菜单(菜单失去焦点),我正在尝试让具有多层的导航栏菜单折叠。我尝试过

$(.dropdown-toggle).blur(function () {.....

但一直无法让任何东西正常工作。有没有人这样做过?根据 bootstrap 的 collapsing content 文档,它们提供了一个按钮来折叠内容的功能,但理论上,这应该是一个非常简单的脚本,不是吗?

http://v4-alpha.getbootstrap.com/components/navbar/#collapsing-content

你应该使用 $('.dropdown-toggle').focus(function(){}); 对于失焦使用 $('.dropdown-toggle').focusout(function(){});

您还可以在 css 中使用 .dropdown-toggle:focus {...} 来实现您想要的目标。

The :focus pseudo class in CSS is used for styling an element that is currently targeted by the keyboard, or activated by the mouse.

p.s 我不知道这是否是一个打字错误,但您在选择 .dropdown-toggle class 和 jquery[ 时错过了 '' =15=]

我能够使用模糊解决这个问题,尽管建议的 focusout 也能正常工作。问题是制表符实际上发生在 a 标签上,我试图检测 li 级别的焦点丢失。愚蠢的错误,但我想我可能不是世界上唯一遇到这个问题的人。