2011-08-17 29 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