shown.bs.dropdown事件永远不会触发

时间:2016-08-05 07:18:59

标签: jquery html css twitter-bootstrap

我在这里缺少什么。我正在尝试在点击汉堡包菜单时收听下拉菜单事件,并显示菜单。我认为这可能是一个标记问题,但无法看出我做错了什么。

<div id="head-nav">
<nav class="navbar navbar-default navbar-fixed-top head-nav">
    <div class="container-fluid">
        <div class="navbar-header head-nav__header">

            <button type="button" class="navbar-toggle head-nav__hamburger" data-toggle="collapse"
                    data-target="#bsm-navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>

            <a class="navbar-brand head-nav__logo" href="#">
             </a>
        </div>


        <div class="navbar-collapse collapse" id="bsm-navbar-collapse">
                <!-- mobile -->
                <ul class="nav navbar-nav hidden-sm hidden-md hidden-lg navbar-right">
                    <li><a href="/" class="head-nav__link">Home</a></li>
                    <li><a href="/home-loans/" class="head-nav__link">Compare Home Loans</a></li>
                    <li><a href="/special-offer/" class="head-nav__link">Special Offer</a></li>
                    <li><a href="/rate-chaser/" class="head-nav__link">Health Check</a></li>
                    <li><a href="/about-us/" class="head-nav__link">About Us</a></li>
                </ul>

                <!-- desktop -->
                <ul class="nav navbar-nav navbar-right hidden-xs">
                    <li><a href="/home-loans/" class="head-nav__link head-nav__link--first">Compare Home Loans</a>
                    </li>
                    <li><a href="/special-offer/" class="head-nav__link">Special Offer</a></li>
                    <li><a href="#" class="head-nav__link">Big Bank Fight</a></li>
                    <li><a href="/rate-chaser/" class="head-nav__link">Health Check</a></li>
                    <li><a href="/home-loan-calculator/" class="head-nav__link head-nav__link--last">Calculators</a>
                    </li>
                </ul>
        </div>

    </div>
</nav>

/* Latest compiled and minified JavaScript included as External Resource */
$(function() {
     console.log('ready...');
      $('*').on('shown.bs.dropdown', function () {
      // never called up, although I have bound to everything....
           console.log('called');
      });
 });

JS Fiddle

2 个答案:

答案 0 :(得分:1)

试试这个::

$(function() {
      $('#bsm-navbar-collapse').on('shown.bs.collapse', function () {
      console.log('called');
    });
 });

答案 1 :(得分:0)

你正在打电话给'崩溃&#39;元素与您的按钮,而不是下拉列表。试试:

$('*').on('shown.bs.collapse', function () {
      // never called up, although I have bound to everything....
           console.log('called');
      });