How to enable Bootstrap tooltip on disabled button?

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

    You can't get the tool-tip to show on a disabled button. This is because disabled elements don't trigger any events, including the tool-tip. Your best bet would be to fake the button being disabled (so it looks and acts like its disabled), so you can then trigger the tool-tip.

    Eg. Javascript:

    $('[rel=tooltip].disabled').tooltip();
    
    $('[rel=tooltip].disabled').bind('click', function(){
         return false;
    });
    

    Instead of just $('[rel=tooltip]').tooltip();​

    HTML:


    JSFiddle: http://jsfiddle.net/BA4zM/75/

提交回复
热议问题