Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载(';file.html#target.subTarget';)不工作_Javascript_Jquery_Load - Fatal编程技术网

Javascript 加载(';file.html#target.subTarget';)不工作

Javascript 加载(';file.html#target.subTarget';)不工作,javascript,jquery,load,Javascript,Jquery,Load,我正在努力 $(destino).load('all.html #reservas_1',function(){ console.log('cargado!'); alert($(destino).html()); //the alerts shows HTML }).show(); 而且效果很好 但是传入的html代码被一个包装,它有一个display none,所以我正在尝试 $(destino).load('all.html

我正在努力

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

但是传入的html代码被一个
包装,它有一个display none,所以我正在尝试

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

知道为什么吗?是因为我使用类作为选择器,还是因为我无法加载子目标?

加载后可能需要更新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规范,它不应该是两个ID相同的元素)。所以,如果您使用更复杂的选择器,它可能返回元素数组,而jQuery不知道如何合并所有元素

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


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

能否显示所有.html中的内容?您的第一段代码是否会提醒包含“.content”类的元素?是的,但是.load将使用.content div加载destino中的内容。哦..抱歉,我已经修复了示例。现在我明白了,你只需要打开元素;这句话不会删除.content包装,而是删除$(destino).html($(destino.find('.content').html());你认为有更好的解决方案吗?如果我们讨论的是性能,那么在这两种情况下都是一样的。如果替换html内容的解决方案适合您,请使用它。实际上,我第一次用html编写示例(但忘了在元素中输入)。