它使用div在身体上工作.它不使用get

Th3*_*B0Y 2 html javascript jquery get click

状态:工作

运行顺畅 - 点击工作

jQuery的

 $("document").ready(function(){

    $("#test").click(function(){
        alert("abc");
    });     
 });
Run Code Online (Sandbox Code Playgroud)

CSS

.blue {
background-color:blue;
}
Run Code Online (Sandbox Code Playgroud)

标记正文

<body>
<div class="blue" id="test">Testing code</div>
</body>
Run Code Online (Sandbox Code Playgroud)

状态:不工作

成功添加文件和div test,但点击不起作用

jQuery的

 $("document").ready(function(){

    $.get("new.php", {
         // this math avoids IE from crashing
         nbRandom: Math.random() 
         },
         function(data){
         $("body").html(data);
         });

    $("#test").click(function(){
        alert("abc");
    });   
 });
Run Code Online (Sandbox Code Playgroud)

CSS

.blue {
background-color:blue;
}
Run Code Online (Sandbox Code Playgroud)

标记正文

<body>
</body>
Run Code Online (Sandbox Code Playgroud)

有谁知道怎么做?

Jon*_* M. 5

该方法get是异步的,这意味着当ajax请求仍在运行时,流将继续,最好的解决方案是将click处理程序放入get回调中.

$("document").ready(function(){

$.get("new.php", {
     // this math avoids IE from crashing
     nbRandom: Math.random() 
     },
     function(data){
       $("body").html(data);
       $("#test").click(function(){
         alert("abc");
       });   
     });


});
Run Code Online (Sandbox Code Playgroud)