Disable a link in Bootstrap

前端 未结 6 1585
挽巷
挽巷 2021-02-03 16:40

The first example didn\'t work. I need to have always a list to disable links? Or what is wrong with my first demo?

Disabl         


        
相关标签:
6条回答
  • 2021-02-03 17:07

    It seems that Bootstrap doesn't support disabled links. Instead of trying to add a Bootstrap class, you could add a class by your own and add some styling to it, just like this:

    a.disabled {
      /* Make the disabled links grayish*/
      color: gray;
      /* And disable the pointer events */
      pointer-events: none;
    }
    <!-- Make the disabled links unfocusable as well -->
    <a href="#" class="disabled" tabindex="-1">Link to disable</a><br/>
    <a href="#">Non-disabled Link</a>

    0 讨论(0)
  • 2021-02-03 17:12

    You cant set links to "disabled" just system elements like input, textfield etc.

    But you can disable links with jQuery/JavaScript

    $('.disabled').click(function(e){
        e.preventDefault();
    });
    

    Just wrap the above code in whatever event you want to disable the links.

    0 讨论(0)
  • 2021-02-03 17:13

    If what you're trying to do is disable an a link, there is no option to do this. I think you can find an answer that will work for you in this question here.

    One option here is to use

    <a href="/" onclick="return false;">123n</a>
    

    Disabled href tag

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

    I think you need the btn class.
    It would be like this:

    <a class="btn disabled" href="#">Disabled link</a>
    
    0 讨论(0)
  • 2021-02-03 17:22

    I just removed 'href' attribute from that anchor tag which I want to disable

    $('#idOfAnchorTag').removeAttr('href');
    
    $('#idOfAnchorTag').attr('class', $('#idOfAnchorTag').attr('class')+ ' disabled');
    
    0 讨论(0)
  • 2021-02-03 17:23

    I just created my own version using CSS. As I need to disabled, then when document is ready use jQuery to make active. So that way a user cannot click on a button until after the document is ready. So i can substitute with AJAX instead. The way I came up with, was to add a class to the anchor tag itself and remove the class when document is ready. Could re-purpose this for your needs.

    CSS:

    a.disabled{
        pointer-events: none;
        cursor: default;
    }
    

    HTML:

    <a class="btn btn-info disabled">Link Text</a>
    

    JS:

    $(function(){
        $('a.disabled').on('click',function(event){
            event.preventDefault();
        }).removeClass('disabled');
    });
    
    0 讨论(0)
提交回复
热议问题