2011-08-10 25 views

回答

0

的见jQuery.ajax办法做到这一点不jQuery是使用document.createDocumentFragment

ajax({ //Your preferred method 
    done: function(response){ 
     var myDom = document.createDocumentFragment(); 
     myDom.innerHTML = response.responseText; 
     // your manipulations same as you would with "document" 
     document.appendChild(myDom); 
    } 
}); 

资源:

1

这绝对不是不可能的。你只需要一种方法来解析它。最简单的方法实际上是将其附加到隐藏容器中的页面上,然后执行所需的任何DOM操作。然后,您可以重新定位html或在适当位置显示它。

如果您使用的是jQuery,那么您实际上可以在您返回的html字符串上执行任何jQuery操作。但是,在某些较旧的浏览器中,这样做性能不佳。

0

如果您正在使用jQuery,你可以尝试以下的(注意,这可能是非常耗费资源的,这取决于你加载的页面大小):

$.ajax({ 
    /*parameters here*/ 
    success: function(data,textStatus){ 
     processData(data); 
    } 
}); 

function processData(data){ 
    //this line creates jQuery object that contains DOM model for loaded page 
    var page = jQuery(data); 

    page.find('#id-of-element-to-add-some-class').addClass('*your class*'); 
    page.find('#table').addClass('myTable'); //adds class myTable to all tables in the document 
    //placeholder for loaded page content. Could be something like $('#placeholder') 
    var target_element = document; 

    $(target_element).append(page); 
} 

的细节

相关问题