jQuery,单击“删除”使所有项目消失,但在刷新时这些项目又返回,只有删除的项目消失了

麦克·奥斯卡·回声

我有点理解为什么会这样,但是我不知道如何解决。

HTML标记:

<tr>
    <th>Attachment</th>
    <td>
        <ul>{% for attachment in lineup.attachments %} {% if lineup.obsolete %}
            <li>{{ attachment.name}}</li>{% else %}
            <!-- this will show just the last file -->{# set attachment = lineup.attachments|last #}
            <li><a href='http://files.example.com/{{ attachment.file_url }}' id='{{ attachment.id }}'>{{ attachment.name }}</a>
                <!-- remove attachment link -->{% if perm.remove_files %}
                <input type='hidden' class='id' value='{{ attachment.id }}' /><a class='remove_file' href='javascript:void(0)' style="margin-left: 20px;">Remove</a>{% endif %}</li>{% endif %} {% endfor %}</ul>
    </td>
</tr>

jQuery删除:

$(document).ready(function(){
    $('.remove_file').click(function(){
        $this = $(this);
        $id = $this.parent().find('.id').val();
        if(confirm('Are you sure you want to delete this file?')){
            $.get('phplib/remove_lineup_attachment.php',{ id: $id }, function(){
                $this.parent().parent().remove();
            });
        }
    });
});

因此,它正在从数据库中删除我要删除的正确附件。问题是,如果我有5个附件显示,当我单击“删除附件”时#5,它们全部消失,然后在刷新页面时,它们全部恢复,除了#5我删除的那个。

我的附件部分如下所示:http : //i.imgur.com/wZSlkWU.png

我是

假设您要删除<li>,而不是<ul>(这是您当前使用的目标.parent().parent()),那么以下方法将为您工作:

$this.parent().remove();

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档