【问题标题】:Jquery get content with ajax and appendTo idJquery使用ajax和appendTo id获取内容
【发布时间】:2012-05-16 18:46:27
【问题描述】:

我使用 ajax 加载第二个页面,并希望将该页面中的特定 id 附加到当前页面。

function Content() {
    $("ul.tabs li a").click(function() {
    $.ajax({ 
        url: $(this).attr('href'),
        success: function(response) {
            $(response).find('ul#image-gallery-items').appendTo('ul#image-gallery-items');
        }
    });
    return false;
    })
}

我错过了什么?

【问题讨论】:

  • 什么不起作用? “我错过了什么?” 问题中有很多信息......
  • 您要附加一个ul 作为另一个/相同ul 的直接子代?你的意思是$(response).find('ul#image-gallery-items li') 吗?
  • @F.Calderan。是同一个身份证。缺少信息...
  • 哦抱歉 :D.. 好吧,我收到了请求,但它不会附加它.. 没有发生:P
  • 我试过这个:$("#image-gallery-items").html($(response).find("#image-gallery-items").children());但这只是给了我一个空的

    标签: jquery ajax appendto


    【解决方案1】:

    您也可以使用 jQuery load 函数加载页面片段:

    $("ul.tabs li a").click(function() {
        $('#image-gallery-items').load(this.href + ' #image-gallery-items');
        return false;
    })​
    

    在这种情况下,您可以使用 附加 元素:

    $("ul.tabs li a").click(function() {
        $('<div></div>').load(this.href + ' #image-gallery-items').children().appendTo('#image-gallery-items');
        return false;
    })​
    

    【讨论】:

    • 谢谢,但我需要使用 $.ajax 方式
    • (我有绑定到 ajax 函数的东西。例如加载器图像等。)
    猜你喜欢
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-10
    • 2013-06-06
    • 2011-09-25
    • 2016-03-14
    相关资源
    最近更新 更多