2014-03-06 24 views
0

我有3頁:index.php,主頁有update.jsupdate.php由AJAX創建的項目不響應jQuery選擇器

我有一張表index.php。我通過AJAX使用update.jsupdate.php從數據庫更新表。

問題是,更新後表中沒有任何內容響應jQuery選擇器。

下面是代碼:

的index.php

<html> 
<head> 
    <title>Hello!</title> 
    <script src="jquery-2.0.3.min.js"></script> 
    <script src="update.js"></script> 
    <style> 
    img#pageloading 
    { 
     display: none; 
     position: fixed; 
     padding-top: 350px; 
     padding-left: 50%; 
    } 
    </style> 
</head> 
<body> 
<table border="1"> 
<thead> 
<th>first</th> 
<th>second</th> 
<th>third</th> 
</thead> 
<?php 
for($i=1;$i<=3;$i++) 
{ 
    ?> 
    <tr id="row<?=$i;?>"> 
    <td>first<?=$i;?></td> 
    <td>second<?=$i;?></td> 
    <td>third<?=$i;?></td> 
    </tr> 
    <?php 
} 
?> 
<img src="../submit/loading.gif" id="pageloading" /> 
</table> 
<button id="update">update</button> 
</body> 
</html> 

update.js

$(document).ready(function(){ 
    $("#update").click(function(){ 
     $("img#pageloading").css("display", "inline"); 
     $("#row1").load("update.php", function() { 
      $("img#pageloading").css("display", "none"); 
     }); 
    }); 
    $(".update2").click(function(){ 
     alert("button update2"); 
    }); 
}); 

update.php

​​3210
+0

如果有更好的標題請寫在這裏,我將編輯 – robert

+0

我想知道爲什麼有人下來這個投票問題 – robert

回答

4

你加載與阿賈克斯的元素,所以你需要委派的事件處理程序

$(document).ready(function(){ 
    $("#update").click(function(){ 
     $("img#pageloading").css("display", "inline"); 
     $("#row1").load("update.php", function() { 
      $("img#pageloading").css("display", "none"); 
     }); 
    }); 
    $("#row1").on('click', ".update2", function(){ 
     alert("buttong update2"); 
    }); 
}); 
+0

哦,我忍受很多看到這 – robert

+0

我不能接受這個問題,現在等待,我會接受它 – robert

+0

@robert - 當然,我會等! – adeneo