【问题标题】:jQuery Ajax - adding new Elements to DOMjQuery Ajax - 向 DOM 添加新元素
【发布时间】:2010-11-26 15:50:37
【问题描述】:

我试图弄清楚如何管理动态加载的列表以使用工具提示。 当链接具有标题标签时,我希望启动工具提示功能。 但我需要将新元素添加到 DOM,以便函数“看到”标题元素。

这是它现在的样子: 工具提示有效,但不适用于加载的元素。

$(document).ready(function() {
    $("#home").click(function(){
        $(".content ").load("start.html");
    });
    $("[title]").style_my_tooltips({ 
        tip_follows_cursor: "on",
        tip_delay_time: 300 
    });

我用 bind 和 live 进行了尝试,但对我没有任何帮助。 我尝试使用 live() 函数:

$("#home").live("click", function(){
    $(".content ").load("start.html");          
});

没用。

帮助表示赞赏。

向马克斯打招呼

【问题讨论】:

    标签: ajax dom jquery


    【解决方案1】:

    您必须在新内容上再次运行插件,如下所示:

    $("#home").click(function(){
      $(".content").load("start.html", function() {
        $("[title]", this).style_my_tooltips({ 
          tip_follows_cursor: "on",
          tip_delay_time: 300 
        });
      });
    });
    

    通过使用this 作为$("[title]", this) 中的上下文,我们只在您刚刚加载的.content 元素中寻找新的[title] 元素。

    【讨论】:

    • 像魅力一样工作!谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 2012-05-18
    • 2016-05-11
    • 2014-09-14
    相关资源
    最近更新 更多