2010-01-28 35 views
0

我有this ajax function jquery。 (http://pastie.org/798788如何使用jQuery生成ajax後執行另一個動作?

輸出結果如下。

<div class="content"> 
    <h1>Latest Messages or Task To Do</h1> 

    <ul style="display: block;" id="message_ul"> 
    <li class="86"> 
<div class="listbox"><span class="user"> 
<strong>Administrator</strong></span> 
<span class="date">2010-01-28 08:57:43</span> 
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/86" 
class="todo">to do</a> 
<span class="msg">Change links in message, to do, completed 
and delete to anchor </span> 
</div> 
    </li> 

<li class="85"> 
<div class="listbox"><span class="user"> 
<strong>Administrator</strong></span> 
<span class="date">2010-01-28 08:51:15</span> 
<a href="http://127.0.0.1/ci_backendpro2/index.php/messages/admin/changestatus/85" 
class="todo">to do</a> 
<span class="msg"> meta tag keywords and 
description should show from page input/database </span> 
</div> 
</li> 

<li class="84"> 
... 
... 

現在我正在嘗試添加class =「todo」的另一個ajax。但是,當我嘗試這個測試。它不警告。它執行php函數。

$(".todo").click(function(){ 
    event.preventDefault(); 
    alert("hei"); 

}); 

我不知道爲什麼。是因爲它是由ajax創建的嗎?

是否與綁定有關?

我該如何讓它工作?

我很感謝您的幫助。

附加信息。 順便說一句,我使用codeigniter。 其他php functions are here(http://pastie.org/798802)

回答

2

看起來您需要使用live風格的事件綁定將事件對象命名爲點擊處理程序的參數。

$(".todo").live('click', function(event) { 
    event.preventDefault(); 
    ... 
}); 
+0

就是這樣。謝謝。 – shin 2010-01-28 15:07:32

1

你需要使用live事件:

$(".todo").live('click', function() { // <- Extend the "click" event to every .todo element created in the future 
    event.preventDefault(); 
    alert("hei"); 
}); 
+0

它仍然不警告。它執行php。 – shin 2010-01-28 14:56:08

0

不知道我完全理解的一切是怎麼回事。但是,如果在執行「綁定」功能後插入類'todo'的鏈接,則需要: a)重新調用綁定函數(首先解除綁定)。 b)使用jquery live函數,以便自動附加到任何新的「待辦事項」類。

相關問題