How to enable Bootstrap tooltip on disabled button?

后端 未结 18 2488
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 23:18

I need to display a tooltip on a disabled button and remove it on an enabled button. Currently, it works in reverse.

What is the best way to invert this behaviour?

18条回答
  •  心在旅途
    2020-11-29 00:10

    For Bootstrap 3

    HTML

    
    

    CSS

    button { position:relative; }
    
    .sp-btn-overlap { 
        position:absolute; 
        top:0; 
        left:0; 
        height:100%; 
        width:100%; 
        background:none; 
        border:none; 
        z-index:1900;
    }
    

    JS

    $('button .sp-btn-overlap')
        .popover({
            trigger: 'hover',
            container: 'body',
            placement: 'bottom',
            content: function() {
                return $(this).parent().prop('disabled')
                        ? $(this).data('hint')
                        : $(this).parent().data('hint');
                }
            });
    

    $('button .sp-btn-overlap')
      .popover({
        trigger: 'hover',
        container: 'body',
        placement: 'bottom',
        content: function() {
          return $(this).parent().prop('disabled')
                      ? $(this).data('hint')
                      : $(this).parent().data('hint'); }
      });
    button {
      position:relative; /* important! */
    }
    
    .sp-btn-overlap {
      position:absolute;
      top:0;
      left:0;
      height:100%;
      width:100%;
      background:none;
      border:none;
      z-index:1900;
    }
    
    
    
    
    
    
    
    
    

提交回复
热议问题