Disabled dropdown menu items using twitter bootstrap

前端 未结 8 1083
挽巷
挽巷 2021-02-03 20:16

I use markup to display a dropdown menu using Twitter Bootstrap.

相关标签:
8条回答
  • 2021-02-03 20:27
    <div class="dropdown-menu">
      <a class="dropdown-item" href="#">Regular link</a>
      **<a class="dropdown-item disabled" href="#">Disabled link</a>**
      <a class="dropdown-item" href="#">Another link</a>
    </div>
    

    Add .disabled to items in the dropdown to style them as disabled. Source: www.getbootstrap.com

    0 讨论(0)
  • 2021-02-03 20:29

    YES, Bootstrap has a predefined class with all necessary styling you need. You can simply add disabled class to whichever <li> you want

    0 讨论(0)
  • 2021-02-03 20:31

    I prefer this (LESS):

    /* Disable link */
    a.disabled, 
    a.disabled:visited ,
    a.disabled:active,
    a.disabled:hover {  
      color: #999 ;
      cursor: default;
    }
    .dropdown-menu {
      a.disabled, 
      a.disabled:visited ,
      a.disabled:active,
      a.disabled:hover {  
        color: #999 ;
        cursor: default;
        background-color: white;
      }
    }
    
    0 讨论(0)
  • 2021-02-03 20:35

    Just to add to Andres answer (don't have enough reputation to add comments :( ). You need to return false from the event handler or it might continue executing other handlers.

    $(".disabled-link").click(function(event) {
      event.preventDefault();
      return false;
    });
    
    0 讨论(0)
  • 2021-02-03 20:40

    To disable the the dropdown use:

    $('.dropdown-toggle').addClass('disabled');
    

    To enable it back:

    $('.dropdown-toggle').removeClass('disabled');
    
    0 讨论(0)
  • 2021-02-03 20:40

    Similar to above you can use:

        li.disabled > a {
        color:#aaa !important;
        }
    

    This way you are keeping the same bootstrap default class for disabled links and implement the preventDefault() Javascript to disabled the link.

    $(".disabled").click(function(event) {
    event.preventDefault();
    return false;
    });
    
    0 讨论(0)
提交回复
热议问题