我是java脚本的新手。当页面中已经存在表格时,我用于删除表格行的代码可以正常工作,但是如果我通过 ajax 调用从另一个页面加载表格,则它不起作用..请帮我解决这个问题.. java 脚本在这里
$(document).ready(function()
{
$('table#delTable td a.delete').click(function()
{
if (confirm("Are you sure you want to delete this row?"))
{
var id = $(this).parent().parent().attr('id');
var data = 'id=' + id ;
var parent = $(this).parent().parent();
$.ajax(
{
type: "POST",
url: "delete_row.php",
data: data,
cache: false,
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
}
});
// style the table with alternate colors
// sets specified color for every odd row
$('table#delTable tr:odd').css('background',' #FFFFFF');
});
html代码
<table id="delTable">
<tr id="ripon">
<td align="left">Ipsum</td>
<td align="center">19</td>
<td align="center">17</td>
<td align="center"><a href="#" class="delete" style="color:#FF0000;"><img alt="" align="absmiddle" border="0" src="img/delete.png" /></a></td>
</tr>
<tr id="rukon">
<td align="left">Dolor</td>
<td align="center">55</td>
<td align="center">12</td>
<td align="center"><a href="#" class="delete" style="color:#FF0000;"><img alt="" align="absmiddle" border="0" src="img/delete.png" /></a></td>
</tr>
<tr id="sumon">
<td align="left">Sit</td>
<td align="center">11</td>
<td align="center">18</td>
<td align="center"><a href="#" class="delete" style="color:#FF0000;"><img alt="" align="absmiddle" border="0" src="img/delete.png" /></a></td>
</tr>
<tr id="mamun">
<td align="left">Amet</td>
<td align="center">29</td>
<td align="center">27</td>
<td align="center"><a href="#" class="delete" style="color:#FF0000;"><img alt="" align="absmiddle" border="0" src="img/delete.png" /></a></td>
</tr>