How to enable Bootstrap tooltip on disabled button?

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

    Here is some working code: http://jsfiddle.net/mihaifm/W7XNU/200/

    $('body').tooltip({
        selector: '[rel="tooltip"]'
    });
    
    $(".btn").click(function(e) {
        if (! $(this).hasClass("disabled"))
        {
            $(".disabled").removeClass("disabled").attr("rel", null);
    
            $(this).addClass("disabled").attr("rel", "tooltip");
        }
    });
    

    The idea is to add the tooltip to a parent element with the selector option, and then add/remove the rel attribute when enabling/disabling the button.

提交回复
热议问题