How to enable Bootstrap tooltip on disabled button?

后端 未结 18 2461
爱一瞬间的悲伤
爱一瞬间的悲伤 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:00

    Working code for Bootstrap 3.3.6

    Javascript:

    $('body').tooltip({
      selector: '[data-toggle="tooltip"]'
    });
    
    $(".btn").click(function(e) {
     if ($(this).hasClass("disabled")){
       e.preventDefault();
     }
    });
    

    CSS:

    a.btn.disabled, fieldset[disabled] a.btn {
      pointer-events: auto;
    }
    

提交回复
热议问题