简体   繁体   English

禁用/销毁后重新应用Twitter Bootstrap工具提示

[英]Reapply Twitter Bootstrap Tooltip after disable/destroying

I have a simple question. 我有一个简单的问题。 I have data displayed from a selected item in a table, so it changes frequently. 我从表中的选定项目中显示了数据,因此它经常更改。 I am using this to check for overflow: 我正在使用它来检查溢出:

if (event.target.offsetWidth < event.target.scrollWidth) {

            if ($(event.target).attr('tooltip')) {
                $(event.target).tooltip('enable');
            } else {
                $(event.target).tooltip({
                    title: $(event.target).text(),
                    placement: 'bottom',
                    animation: false
                });
                $timeout(function () {
                    $(event.target).tooltip('show');
                });
            }
        } else {
            $(event.target).tooltip('disable');
        }

This works, but I cannot get the tooltip to show after being disabled. 此方法有效,但是在禁用后我无法显示工具提示。 I have tried destroy in place of disable (which doesn't appear in the docs ) and adding the whole tooltip after it is destroyed. 我试过使用destroy代替disable(它未出现在docs中 )并在销毁后添加整个工具提示。 To no avail. 无济于事。 How can I replace a destroyed/disabled tooltip? 如何替换已损坏/已禁用的工具提示?

If I am dynamically disabling and re-enabling the tooltip, I clear the 'bs.tooltip' first before calling the show. 如果要动态禁用和重新启用工具提示,请在调用节目之前先清除'bs.tooltip' Something like this: 像这样:

$('#element').data('bs.tooltip', null);
$('#element').tooltip({ placement: 'bottom' });
$('#element').tooltip('show');

And to disable: 并禁用:

$('#element').tooltip('disable');

Try this out this will work fine for you 试试这个,这对你来说很好

$('#element').tooltip({
    title: 'My first tooltip'
}); // Add the tooltip

$('#element').tooltip('show'); // Show the tooltip

$('#element').tooltip({
    title: 'I want to change this tooltip'
}); // Try to change the tooltip

$('#element').tooltip('show'); // The tooltip will still say 'My first tooltip'

/****************************/

$('#element').data('tooltip', false); // Remove the previous tooltip

$('#element').tooltip({
    title: 'This is the new tooltip'
}); // Try to change the tooltip

$('#element').tooltip('show'); // The tooltip should say 'This is the new tooltip'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM