求助:单击删除链接后,没有任何反应?

我试图使以下代码在最近5到6个小时内都能正常工作,但是没用。有人能帮助我了解此代码有什么问题吗? 单击删除链接后,没有任何反应。

表格:

<table id="links">
    <tr id="record-<?php echo $row['FeePaymentId']; ?>">
        <td><?php echo $row['MasterEntryValue']; ?></td>
        <td><?php echo $row['Amount']; ?></td>
        <td><a href="#" class="delete">delete</a></td>
    </tr>
</table>

JavaScript:

$('table#links 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: "DeleteRow.php",
            data: data,
            cache: false,
            success: function() {
                parent.fadeOut('slow', function() {$(this).remove();});
            }
        });                
    }
})

There is nothing wrong with your JS, if there are no other JS errors in the page and the click event is not firing at all. Than just place your JS code inside $(document).ready(function () {});:

$(document).ready(function () {
    $('table#links 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: "DeleteRow.php",
                   data: data,
                   cache: false,

                   success: function()
                   {
                        parent.fadeOut('slow', function() {$(this).remove();});
                   }
             });                
        }
    })
});

The selector isn't correct, try this: $('#links a.delete') which will select all anchor elements with class 'delete' under the element with id 'links'

jsfiddle