我有一个简单的下拉菜单,我在内联文本链接上显示。我使用jQuery点击事件来显示下拉菜单,当点击链接时。当用jQuery在页面中点击某处时关闭下拉菜单?
我想要做的是有一个点击任何地方时,下拉菜单回到隐藏状态。现在你必须再次点击链接关闭菜单。
演示http://codepen.io/jasondavis/pen/sFpwK?editors=101
jQuery的
// Show Dropdown Menu when link is clicked
$(function(){
$(".inline-dropdown-menu").click(function(e){
$(this).find(".inline-dropdown-menu-list:first").toggle();
e.preventDefault(); // Stop navigation
});
});
HTML
<span class="inline-dropdown-menu">
<a href="">My Link that reveals a DropDown Menu when clicked on<span class="caret"></span></a>
<ul class="inline-dropdown-menu-list">
<li class="bottomBorder">
<a href="" tabindex="-1">alphabetically</a>
</li>
<li>
<a href="" tabindex="-1">2. the first report, alphabetically</a>
</li>
<li>
<a href="" tabindex="-1">3. the first report, alphabetically</a>
</li>
</ul>
</span>
'e.stopPagagation();'似乎是魔法的地方 – JasonDavis 2014-10-20 07:11:24
@jasondavis的确的确是 – Kaustav 2014-10-20 08:45:15