jQuery $.ajax第一次有效,但在后续点击时无效。

3

第一次点击删除链接时,一切都正常,但是后续的点击只会删除记录,而不会刷新“引用”div。

我不确定我在这里忽略了什么。

我的.js文件:

$('.deleteRow').live('click', function (e) {
    if (confirm('Delete?')) {
        $.ajax({
            type: 'POST',
            url: this.href,
            cache: false,
            dataType: 'html',
            success: function (response) {
                $('#quotes').replaceWith(response);
                $('#quotesTable').tablesorter().tablesorterPager({ container: $('#pager'), positionFixed: false });
            }
        });
    }
    return false;
});

而且HTML:

<tr>
    <td>
        Now is the time for all good men to come to the aid of their parties.
    </td>
    <td>

    </td>
    <td>
        7/6/2010 10:13:44 PM
    </td>

    <td> <a class="editRow" href="/Quote/Edit/2">Edit</a></td>
    <td> <a class="deleteRow" href="/Quote/Delete/2">Delete</a></td>
</tr>

<tr>
    <td>
        I&#39;m a loser
    </td>

    <td>
        146
    </td>
    <td>
        7/6/2010 9:11:42 PM
    </td>
    <td> <a class="editRow" href="/Quote/Edit/1">Edit</a></td>
    <td> <a class="deleteRow" href="/Quote/Delete/1">Delete</a></td>
</tr>
1个回答

5

我现在用iPhone查看,无法看到你的所有代码,但你应该使用".html"而不是".replaceWith"。前者替换指定标签内的内容,后者还会抹掉标签。


1
+1 - 因为我认为你是正确的,而且你正在使用 iPhone 发布答案。这就是敬业精神!:o) - user113716

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接