+ -
当前位置:首页 → 问答吧 → 点击事件没有反应。

点击事件没有反应。

时间:2009-03-15

来源:互联网

creat_log.html 内容
<span id="test" >Answer</span>

-----------------------------------------------------------------------------------------------------------------------------------------------------------
    
$("#creat_log").click(function(){
                
    $("#content").load("creat_log.html");    //载入creat_log.html内容            
        
});

$("#test").click(function(){     //这里绑定的事件无法执行
    
    alert('aaaa');
  });
    

问题出在哪?点击事件没有反应。    

作者: lmss82   发布时间: 2009-03-15

因为你绑定事件的时候,#test还没加载完
这段代码是异步执行的。

你应当这样写

$("#creat_log").click(function(){
                
    $("#content").load("creat_log.html",function(){

$("#test").click(function(){     //这里绑定的事件无法执行
    
    alert('aaaa');
  });
    
    });    //载入creat_log.html内容            
        
});

作者: shawphy   发布时间: 2009-03-15

明白,使用回调函数重新绑定事件。

作者: lmss82   发布时间: 2009-03-16