[英]load('file.html #target .subTarget') not working
I am trying to我在尝试着
$(destino).load('all.html #reservas_1',function(){
console.log('cargado!');
alert($(destino).html()); //the alerts shows HTML
}).show();
And it works fine,而且效果很好,
But the incoming html code is wrapped by a <div class="content">
which has a display none so I am trying但是传入的 html 代码被一个<div class="content">
包裹,它没有显示所以我正在尝试
$(destino).load('all.html #reservas_1 .content',function(){
console.log('cargado!');
alert($(destino).html()); //the alert shows black string
}).show();
Any idea why?知道为什么吗? Is it because I am using a class as selector or is that I can't load a subtarget?是因为我使用类作为选择器还是无法加载子目标?
Probably you need to update html after loading:可能您需要在加载后更新 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();
It looks like it allows to use only selector by ID becuase it means that it should be only one element with id on the requested page (by html specification it shouldn't be 2 elements with the same ID).看起来它只允许通过 ID 使用选择器,因为这意味着在请求的页面上它应该只有一个具有 id 的元素(根据 html 规范,它不应该是具有相同 ID 的 2 个元素)。 So, if you will use more complex selectiors it can return array of elements and jQuery don't know how to merge all of them.因此,如果您将使用更复杂的选择器,它会返回元素数组,而 jQuery 不知道如何合并所有元素。
jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. jQuery 使用浏览器的 .innerHTML 属性来解析检索到的文档并将其插入到当前文档中。
You can't get html in such way if you will have array of elements.如果您将拥有元素数组,则无法以这种方式获取 html。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.