簡體   English   中英

禁用/銷毀后重新應用Twitter Bootstrap工具提示

[英]Reapply Twitter Bootstrap Tooltip after disable/destroying

我有一個簡單的問題。 我從表中的選定項目中顯示了數據,因此它經常更改。 我正在使用它來檢查溢出:

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');
        }

此方法有效,但是在禁用后我無法顯示工具提示。 我試過使用destroy代替disable(它未出現在docs中 )並在銷毀后添加整個工具提示。 無濟於事。 如何替換已損壞/已禁用的工具提示?

如果要動態禁用和重新啟用工具提示,請在調用節目之前先清除'bs.tooltip' 像這樣:

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

並禁用:

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

試試這個,這對你來說很好

$('#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