我只是无法让这个(非常简单的)功能正常工作, parents() 似乎没有找到我想要的 div 并将其淡出:(
$('.deleteButton').click( function() {
var img = $(this).attr('href');
img = "../"+img;
var answer = confirm('Are you sure you want to delete this item? (This cannot be undone!)');
if (answer) {
$.ajax({
url: 'scripts/deletePhoto.php',
data: 'img='+img,
type: 'POST',
mode: 'abort',
success: function(){
$(this).parents("div.photo").fadeOut('fast');
}
});
}
return false;
});
HTML
<div class="photo">
<img alt="" src="../static/images/photos/tmp/1.jpg">
<div class="overlay" style="opacity: 0;">
<p class="process success message">
<a href="process_photo.php?img=../static/images/photos/tmp/1.jpg">Process this photo</a>
</p>
<p class="delete error message">
<a href="../static/images/photos/tmp/1.jpg" class="deleteButton">Delete image</a></p>
</div>
</div>
我已经尝试过$(this).parents(".photo").fadeOut('fast');
,$(this).cloest("div.photo").fadeOut('fast');
但没有任何连接:(