任何人都可以帮我这个代码 除了这段代码不起作用
之外,一切正常 $(document).ready(
function()
{
$("a.delete").click(
function ()
{
var cnf = confirm("Are you sure you want to delete this ticket?");
if(cnf){
$.post($(this).attr('href'),
{ "ajx": true },
function(data){
if(data.scs){
/*this piece of code is not working*/
$(this).closest('tr').remove();
/*this piece of code is not working*/
//alert("ticket was deleted");
}
else{
alert("Error:: Ticket could not be deleted."+data.msg);
}
}, "json");
//alert('the requested ticket was deleted.');
}
//alert();
return false;
}
);
}
);
我有一个表,我想删除包含被点击链接的行。
表格行为
<?php while($row = mysql_fetch_assoc($result)): ?>
<tr>
<td><?php echo ++$count; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['eventname']; ?></td>
<td>
<div class="img">
<img class='event' src="../upload/<?php echo $row['image']; ?>" alt="<?php echo $row['image']; ?>"/>
</div>
</td>
<td><?php echo $row['status']; ?></td>
<td><?php echo $row['date']; ?></td>
<td><a href="addticket.php?action=edit&tid=<?php echo $row['id']; ?>">edit</a></td>
<td><a class="delete" href="deleteticket.php?tid=<?php echo $row['id']; ?>" href="#">delete</a></td>
</tr>
<?php endwhile; ?>
UPDATE ::在我的firebug控制台中,我收到错误消息
g.nodeName is undefined
[Break On This Error] "first")return true;m=g;case "last":fo...Type===1||g.nodeName.toLowerCase()===
答案 0 :(得分:0)
以下情况应该有效 - 最近沿着dom行进到下一个“tr”并将其删除
$('a.delete').click(function() {
$(this).closest('tr').remove();
});
答案 1 :(得分:0)
$("table").delegate("a.delete", "click", function(ev) {
if(confirm("Are you sure you wish to delete this row?"))
$(this).closest("tr").remove();
ev.preventDefault();
});