2011-08-17 55 views
0

我有一個網站,它使用分頁。如何啓用動態添加代碼的工具提示?

我使用的工具提示使用下列插件:http://plugins.jquery.com/project/tooltip

我使用AJAX來更新一個div容器。這是代碼:

$(".page-number").live("click", function() 
    { 

     var page = parseInt($(this).html()); 
     var progressbarValue = ((page/$("#NumberOfPages").val()) * 100); 
     var catId = $("#CategoryID").val(); 

     $.ajax({ 
      url: '@Url.Action("QuestionList")', 
      data: { "categoryId": catId, "page": page }, 
      success: function (data) { 
       $("#question-list").html(data); 
       $("#progressbar").progressbar("value", progressbarValue); 
       $("#progresstext").html("<p>" + Math.round(progressbarValue) + "% gennemgået</p>"); 
       EnableDisableToolTip(); 
      } 
     }); 
    }); 

這是爲了使功能/禁用工具提示:

<script type="text/javascript"> 
function EnableDisableToolTip() { 

    var help_text = $("#helptext_checkbox").is(':checked:'); 

    if (help_text) { 
    alert("true"); 
     $(".tooltip").qtip("enable") 
    } 
    else if (!help_text) { 
    alert("false"); 
    $(".tooltip").qtip("disable"); 
    }   
} 
</script> 

當我加載新頁面時,我看不到任何提示,當我在與元件的鼠標懸停類=「工具提示」。另外,當我查看源代碼時,動態添加的代碼不存在。它在第一頁工作,並且class =「tooltip」的源代碼就在那裏。但不是與動態的東西。

我該如何解決這個問題?

[編輯]

的工具提示代碼:

 $(".tooltip").each(function() 
    { 
    $(this).qtip({ 

     show: 'mouseover', 
     hide: 'mouseout', 

     style: { 
      name: 'light', // Inherit from preset style 
      width: { 
       min: 0, 
       max: 250 
       }, 
     }, 

     position: { 
      corner: { 
       target: 'topMiddle', 
       tooltip: 'bottomLeft' 
      }, 
      adjust: { 
       screen: true, 
       scroll: false 

      } 
     } 
    }); 
}); 

回答

0

查看頁面源代碼顯示了被交付給客戶時,最初請求的頁面。它不顯示當前的DOM。

將新內容添加到頁面時,它不知道已經運行的內容。添加內容時,您需要重新掃描工具提示的頁面。

+0

我使用代碼編輯了我的問題,以顯示工具提示,我認爲這是在$(「。tooltip」).qtip(「enable」)上觸發的。你能解釋我如何重新掃描工具提示頁面嗎? – Nanek

+0

您需要再次在Ajax回調中調用'工具提示代碼:'。不只是啓用/禁用的代碼。 – epascarello

+0

感謝您的幫助:) – Nanek

0

EnableDisableToolTip有一個條件來啓用/禁用工具提示($("#helptext_checkbox").is(':checked:'))。您確定在進行ajax調用時會檢查它嗎?我認爲它沒有被檢查,因爲沒有啓用工具提示。

+0

它被選中,因爲它提醒真實 – Nanek