Bootstrap 3: how to make head of dropdown link clickable in navbar

前端 未结 15 853
暗喜
暗喜 2020-12-07 09:23

I\'m using the default navbar and a couple of the list items are dropdowns. I\'m not able to click the link that triggers the dropdown. I know that I could just add a duplic

15条回答
  •  轮回少年
    2020-12-07 10:24

    Here is a small hack based on Bootstrap 3.3 using a bit jQuery.

    A click on a opened dropdown-menu executes the link.

    $('li.dropdown').on('click', function() {
        var $el = $(this);
        if ($el.hasClass('open')) {
            var $a = $el.children('a.dropdown-toggle');
            if ($a.length && $a.attr('href')) {
                location.href = $a.attr('href');
            }
        }
    });
    

提交回复
热议问题