2011-01-10 49 views
0

好傢伙,我有這個腳本:jQuery的後上識別插入HTML

function getList(){ 
$.ajax({ 
    type: "POST", 
    url: "listaPogovorki.php", 
    success: function(msg){ 
    $("#listaPogovorki").html(msg); 
}}); 

} 

getList(); 

這個我稱之爲PHP腳本:

<table> 
<col id="td1"/> 
<col id="td2"/> 
<col id="td3"/> 
<col id="td4"/> 
<tr> 
<td >#ID</td> 
<td >Pogovorka</td> 
<td >Avtor</td> 
<td >Izmeni</td> 
</tr> 
<?php $result = mysql_query("SELECT * FROM $table"); 

while($row = mysql_fetch_array($result)) 
    { 
    ?> 
    <tr> 
    <td><?php echo $row['id'];?></td> 
    <td><?php echo $row['pogovorka'];?></td> 
    <td><?php echo $row['avtor'] ?></td> 
    <td><img class="editImage" src="images/icon_pencil.png" width="16px" height="16px" alt="<?php echo $row['id'];?>"></td> 
    </tr> 
    <?php } 
    mysql_close($con); 
    ?> 

</table> 

現在的問題是,該腳本不承認HTML從PHP腳本返回,所以我不能點擊圖像(從PHP腳本)來解僱一些代碼。例如,如果我使:

$(".editImage").click .... 

它不會工作。

我該如何做這項工作?

回答

0

你可以放置AJAX成功回調裏面$(".editImage").click與新的HTML更新DOM後或使用.live()方法:

$('.editImage').live('click', function() { 
    ... 
}); 
1

您要使用的live function

$('.editImage').live('click', ....); 

或者使用另一個元素作爲event delegate

0

這是.live功能是什麼 - 它甚至結合到還不存在的元素。 (「。editImage」)。live(「click」,function(){});

http://api.jquery.com/live/