简体   繁体   English

load('file.html #target .subTarget') 不工作

[英]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.

相关问题 从链接中删除file.html - stripping file.html out of the link 如何将 file.js 调用到 file.html - How do I call a file.js into a file.html Angular + Webpack:为什么比templte:require(file.html)更好,而不是用templateUrl指定它 - Angular + Webpack: Why is better to templte:require(file.html) than to specify it with a templateUrl 通过Javascript从表单传递一个变量id来打开一个新的file.html - Pass a variable id from a form by Javascript to open a new file.html Cordova 未定义 加载后 file:///android_assets/file.html - Cordova is undefined After loading file:///android_assets/file.html jQM-使用$ .mobile.changePage时Javascript在&#39;file.html&#39;中不起作用 - jQM - Javascript doesn't work in 'file.html' when use $.mobile.changePage 如何在Python Altair Chart.save(file.html)生成的Altair Chart的html文件上显示默认工具提示? - How to display the default tooltip on the html file of a n Altair Chart generated by Python Altair Chart.save(file.html)? 加载文件 javascript 在 html 代码中不起作用 - load file javascript not working in html code jquery .load() 将一个 html 文件包含到另一个不工作的文件中 - jquery .load() to include an html file into another not working Html 元素目标 _blank 不起作用 - Html a element target _blank not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM