Dynamically add a class to Bootstrap's 'popover' container

后端 未结 22 2435
名媛妹妹
名媛妹妹 2020-11-29 18:27

I\'ve thoroughly searched through both StackOverflow and Google, but come up empty. So apologies in advance if this has been asked & resolved already.

NB

22条回答
  •  有刺的猬
    2020-11-29 18:41

    This extend your class from out side bootstrap core class, just add the attribute data-class and an option dataClass: true to your tooltip function

    !function($){   
        $.extend($.fn.tooltip.Constructor.DEFAULTS,{
            dataClass: false
        }); 
        var Tooltip = $.fn.tooltip.Constructor;
            _show = Tooltip.prototype.show;
    
        Tooltip.prototype.show = function (){
            _show.apply(this,Array.prototype.slice.apply(arguments));
    
            if (this.options.dataClass!=="undefined" && this.options.dataClass){
                var that = this;
                var $tip = this.tip();
                if (this.$element.attr("data-class") !== undefined)
                    $tip.addClass(this.$element.attr("data-class"));
            }
        };
    }(jQuery);
    

提交回复
热议问题