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

前端 未结 15 791
暗喜
暗喜 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:20

    Anyone arriving here who wants the quick answer to this problem. Replace the "Dropdown.prototype.toggle" function in your bootstrap.js (or dropdown.js) with the following:

      Dropdown.prototype.toggle = function (e) {
    var $this = $(this)
    
    if ($this.is('.disabled, :disabled')) return
    
    var $parent  = getParent($this)
    var isActive = $parent.hasClass('open')
    
    clearMenus()
    
    if (!isActive) {
        if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) {
            // if mobile we use a backdrop because click events don't delegate
            $('

    On the second click (ie: if the menu item has the class "open") it will first check if the href is undefined or set to "javascript:;" before sending you along your merry way.

    Enjoy!

提交回复
热议问题