下面是显示删除消息“ $(".imagemsg" + counter).html(data);
”的代码。但是它只在第二行删除文件后显示删除消息,这是不正确的,它应该只显示在删除文件的行中。
例如,如果文件从第 3 行删除,则应在第 3 行显示该消息,如果从第 6 行删除文件,则应在第 6 行显示删除消息等。但此时无论是哪一行文件被删除,只有第二行显示删除消息。
var counter = 0;
function stopImageUpload(success, imagefilename){
var result = '';
counter++;
if (success == 1){
result = '<span class="imagemsg'+counter+'">The file was uploaded successfully!</span><br/><br/>';
$('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" image_file_name="' + imagefilename + '">Remove</button><br/><hr/></div>');
}
else {
result = '<span class="imageemsg">There was an error during file upload!</span><br/><br/>';
}
$(".deletefileimage").on("click", function(event) {
var image_file_name = $(this).attr('image_file_name');
jQuery.ajax("deleteimage.php?imagefilename=" + image_file_name)
.done(function(data) {
$(".imagemsg" + counter).html(data);
});
$(this).parent().remove();
});
return true;
}
结果变量在 imageupload.php 中被调用:
打回来:
<script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result ? 'true' : 'false'; ?>, '<?php echo $_FILES['fileImage']['name'] ?>');</script>