我有点理解为什么会发生这种事,但我不知道如何解决。
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上单击delete时,它们都会消失,然后当我刷新页面时,它们都回来了,除了我删除的#5。
附件部分是什么样子:http://i.imgur.com/wZSlkWU.png
发布于 2013-12-20 15:44:26
假设您想要删除<li>,而不是<ul> (这就是您目前使用.parent().parent()的目标),下面的内容应该适用于您:
$this.parent().remove();https://stackoverflow.com/questions/20707098
复制相似问题