Jquery 加载另一个具有DOM更改的页面

Jquery 加载另一个具有DOM更改的页面,jquery,dom,Jquery,Dom,我正在尝试从initial.html不同的html页面加载以下内容: $("#hidden_demo_div").load("modules/another.html", function (data) { var value = $(data).filter("#demo_div"); var html = value.html(); // THERE IS NO <strong>Hello</strong> here!!! } $(“#hidden_

我正在尝试从initial.html不同的html页面加载以下内容:

$("#hidden_demo_div").load("modules/another.html", function (data) {
    var value = $(data).filter("#demo_div");
    var html = value.html(); // THERE IS NO <strong>Hello</strong> here!!!
}
$(“#hidden_demo_div”).load(“modules/other.html”,函数(数据){
var值=$(数据).filter(“#demo_div”);
var html=value.html();//这里没有Hello!!!
}
这里是另一个.html中的一个片段

<html>
    .........................
    <head>
    <script type="text/javascript">
        $(document).ready(function() {
             anotherMethodInvocation();
        });
    </script>
    </head>

    <div id="demo_div"></div>
</html>

.........................
$(文档).ready(函数(){
无热法职业();
});
接下来在JS forother.html我有:

function anotherMethodInvocation() {    
    $("#demo_div").append("<strong>Hello</strong>");
}
函数anotherMethodInvocation(){
$(“#demo_div”)。追加(“你好””;
}
所以问题是为什么我(在我的回调函数中)只得到静态HTML,而不是它的变化

更新1:

a) “#hidden_demo_div”位于initial.html(其中JS代码与.load链接)。 此元素在正文中声明:

b) 即使我把它放在身体上也不起作用 (到一个html文件)


及 (到另一个html文件)



在正文中。

重要的是要意识到,加载远程页面时,
就绪事件已经在主页中发生。这意味着远程页面中用
$(document).ready(function(){}
包装的代码将立即启动

如果远程文件中的代码位于它引用的html之前,它将找不到该html,因为它在代码激发时不存在

在远程页面中尝试此结构:

<div id="demo_div"></div>
<!--  "demo_div" now exists , can run code on it -->
<script type="text/javascript">            
       anotherMethodInvocation();

</script>

无热法职业();

head部分后没有标记。您的结构看起来如何?我是指您的文件以及此方法从何处运行?请提供有关包含anotherMethodInvocation()的JS的更多信息。它是在索引html中链接还是在另一个.html中链接?如果你添加了一个body标记,它就会工作。Fiddle@Bruno不幸的是,不是。你的Fiddle示例没有。加载有趣的调用。
$(文档).ready
相当于设置一个短超时。如果调用时文档已经准备好,它将不会同步运行。请参阅@Esailija,当它在ajax加载页面中使用时,它不会…
ready
已经出现。没有…脚本可以放在头或正文中。正如我所示,您需要将代码放在htm之后的正文中l另一种方法是将脚本放在外部文件中,并在
load
回调中使用
$.getScriot
<div id="demo_div"></div> 
<div id="demo_div"></div>
<!--  "demo_div" now exists , can run code on it -->
<script type="text/javascript">            
       anotherMethodInvocation();

</script>