2015-11-18 67 views
1

我正在使用jQuery工具提示爲Datatable顯示動態內容。加載動態內容時,舊元素的工具提示在加載新內容後保留。 我已經看到完全相同的問題,但接受的答案似乎並沒有在我的情況下工作。 下面的提示,我加入​​到整個文檔Jquery工具提示在動態更改DataTable內容後保留

$(document).tooltip({ 
    position: { 
    my: "center top", 
    at: "center bottom+10", 
    using: function(position, feedback) { 

     $(this).css(position); 
     $("<div>") 
     .addClass("arrow") 
     .addClass(feedback.vertical) 
     .addClass(feedback.horizontal) 
     .appendTo(this); 
    } 
    } 
}); 

的使用更改代碼:如下(按類似的問題的建議)並沒有解決我的問題。

using: function(position, feedback) { 
      /* fix tooltip not hiding problem */ 
      if($(".ui-tooltip").length>1){ 
       // since the new tooltip is already added, there are now 2. 
       // removing the first one fixes the problem 
       $(".ui-tooltip")[0].remove(); 
      } 
      $(this).css(position); 
      $("<div>") 
      .addClass("arrow") 
      .addClass(feedback.vertical) 
      .addClass(feedback.horizontal) 
      .appendTo(this); 
     } 
    } 
}); 

回答

0

這是一個老問題,但一個問題,我最近經歷。我選擇的解決方案是在動態內容重新加載時從頁面中刪除所有工具提示。如果您正在使用DataTables庫,則這將位於drawCallback初始化屬性中。

可以刪除所有的提示是這樣的:

$(".ui-tooltip").remove();