悬停上的引导下拉菜单不起作用,我做错了什么

Bootstrap dropdown on hover not working, what am I doing wrong?

本文关键字:错了 什么 不起作用 下拉菜单 悬停      更新时间:2023-09-26

我正在尝试在 Bootstrap 中打开悬停的下拉菜单,但不知何故它不起作用。我怀疑我的jQuery代码是错误的,但我无法弄清楚是什么?

这是我的 HTML:

<a href="#" id="dropdown-filter" data-target="#"  data-toggle="dropdown">
    <button type="button" class="btn btn-primary">Filters</button>
</a>
<ul class="dropdown-menu pull-right" role="menu">
    <li>
        <div class="results-filter">
            Content goes here
        </div>
    </li>
</ul>

和我的jQuery:

jQuery('#dropdown-filter').hover(function() {
    jQuery(this).find('.dropdown-menu').stop(true, true).delay(100).fadeIn();
 }, function() {
    jQuery(this).find('.dropdown-menu').stop(true, true).delay(100).fadeOut();
});

当我单击顶部时它有效,但当我悬停时则无效。

jQuery(this).find('.dropdown-menu')在这里不起作用,因为.dropdown-menu不是<a>-#dropdown-filter的孩子。

.find()寻找儿童。

使用jQuery(this).next('.dropdown-menu')...