2011-05-02 66 views
0

我從數據庫加載一些HTML(用ajax post請求),它看起來像:JQuery的事件綁定

<div id="slides_control"> 
    <div> 
     <a href="#"></a> 
    </div> 
</div> 

使用HTML我還加載JS代碼:

<script> 
$('#slides_control a').bind('click', function() { 
    alert('achtung'); 
}); 
</script> 

腳本去在html之後(在收到的數據中)。

但是,當我點擊新的HTML內的鏈接,我沒有看到警報。怎麼了?


我也試圖綁在阿賈克斯結束之後:

$.post('page.php', {}, function(data) { 
    document.write(data); 
    $('#slides_control a').bind('click', function() { 
     alert('achtung'); 
    }); 
}); 

沒有幫助我。

+0

你可以跟蹤你的代碼你瀏覽器的開發者工具,看看你點擊一個''元素時會執行什麼? – 2011-05-02 14:16:57

回答

0

嘗試包裝jQuery的電話:

<script> 
$(function(){ 
    $('#slides_control a').bind('click', function() { 
     alert('achtung'); 
    }); 
}); 
</script> 
0

加載數據時執行該腳本。數據加載之前您正在執行此腳本。