2011-11-22 41 views
0

我有负载( 'file.html #target .subTarget')不工作

我试图

$(destino).load('all.html #reservas_1',function(){ 
       console.log('cargado!'); 
       alert($(destino).html()); //the alerts shows HTML 
}).show(); 

,它工作正常,

但进入的HTML代码包由至极有一个显示器没有,所以我想要

$(destino).load('all.html #reservas_1 .content',function(){ 
       console.log('cargado!'); 
       alert($(destino).html()); //the alert shows black string 
     }).show(); 

任何想法为什么?是因为我使用一个类作为选择器或者是我无法加载一个子目标?

+1

你能显示来自all.html的内容吗? – Thys

+0

您的第一段代码是否提醒具有“.content”类的元素? –

+0

@AbdullahBattal是的它确实 –

回答

1

也许你需要加载后更新HTML:

$(destino).load('all.html #reservas_1',function(){ 
      //$(destino).find('.content').unwrap(); 
      $(destino).html($(destino).find('.content').html()); 
      alert($(destino).html()); //the alert shows black string 
    }).show(); 

看起来它允许通过ID监守这意味着它应该与被请求的页面上的ID只有一个元素只使用选择(通过HTML规范它不应该是2个具有相同ID的元素)。因此,如果您将使用更复杂的选择器,它可以返回元素数组,而jQuery不知道如何合并所有元素。

jQuery使用浏览器的.innerHTML属性来解析检索到的文档并将其插入到当前文档中。

如果您有元素数组,您无法以这种方式获取html。

+0

啊哈是的,但.load会加载在destino内容与内容分区.. –

+1

哦..反正,我已经修复了例子。你现在只需要解开元素 – Samich

+0

;该句子不会删除.content包装,而是$(destino).html($(destino).find('。content')。html());确实,你认为更好的解决方案? –