【问题标题】:Tooltip not working with Ajax content工具提示不适用于 Ajax 内容
【发布时间】:2015-06-04 17:59:18
【问题描述】:

我想使用 jQuery UI 中的工具提示功能。当我使用

$('.notice').tooltip();

它不工作,没有任何反应。

我的 HTML 如下所示:

<i title="hello world" id="1" class="fa fa-comment-o notice comment_form"></i>

这很奇怪,因为当我使用它时它可以工作

$(document).tooltip();

我的 HTML 代码来自动态 Ajax 请求。这可能是问题吗?如果是这样,我该如何解决?

【问题讨论】:

    标签: javascript jquery ajax jquery-ui tooltip


    【解决方案1】:

    如果你将它包装在一个 document.ready 中,它会起作用吗?例如

            $(document).ready(function(){
                $('.notice').tooltip();
            });
    

    我怀疑更多是因为您的 jquery/dom 没有按时加载?您在使用第一个代码时是否在控制台中看到任何错误?

    $('.notice').tooltip();
    

    【讨论】:

    • 我已经在使用$(document).ready(function(){,不,我在控制台中没有收到任何错误。
    【解决方案2】:

    也许这...

    $(document).tooltip({
        items: ".notice",
        content: function () {
            return $(this).attr("title");
        }
    });
    

    【讨论】:

    • 谢谢,我想测试一下,但我没有代码了,因为问题已经超过 4 年了 ;)
    • 很抱歉。我忘了看日期。 ;)
    猜你喜欢
    • 2023-03-30
    • 2010-10-10
    • 2023-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    • 1970-01-01
    相关资源
    最近更新 更多