我想在“删除”按钮或换句话说删除函数被调用时删除隐藏的输入,但问题是它下面的代码不会删除输入,我怎样才能根据删除正确的输入文件名哪个被删除?下面是删除正确文件名但不删除隐藏输入的代码(为了测试,我将其更改为文本输入):
function stopImageUpload(success, imageID, imagefilename){
var result = '';
imagecounter++;
if (success == 1){
result = '<span class="imagemsg'+imagecounter+'">The file was uploaded successfully</span>';
$('.hiddenimg').eq(window.lastUploadImageIndex).append('<input type="hidden" name="imgid[]" id="'+imageID+'" value="' + imageID + '" />');
$('.listImage').eq(window.lastUploadImageIndex).append('<div>' + htmlEncode(imagefilename) + '<button type="button" class="deletefileimage" data-imageID="'+imageID+'" data-image_file_name="' + imagefilename + '">Remove</button><br/><hr/></div>');
}
var _imagecounter = imagecounter;
$('.listImage').eq(window.lastUploadImageIndex).find(".deletefileimage").on("click", function(event) {
jQuery.ajax("deleteimage.php?imagefilename=" + $(this).attr('data-image_file_name')).done(function(data) {
$(".imagemsg" + _imagecounter).html(data);
});
$(this).parent().remove();
$(".hiddenimg").parent().remove();
});
return true;
}
下面是文件输入表格:
var $fileImage = $("<form action='imageupload.php' method='post' enctype='multipart/form-data' target='upload_target_image' onsubmit='return imageClickHandler(this);' class='imageuploadform' >" +
"<p class='imagef1_upload_form'><label>" +
"Image File: <input name='fileImage' type='file' class='fileImage' /></label><br/><br/><label class='imagelbl'>" +
"<input type='submit' name='submitImageBtn' class='sbtnimage' value='Upload' /></label>" +
"<input type='hidden' class='numimage' name='numimage' value='" + GetFormImageCount() + "' />" +</p>
"</p><p class='imagemsg'></p><p class='listImage'></p>" +
"<iframe class='upload_target_image' name='upload_target_image' src='/' style='width:0px;height:0px;border:0px;solid;#fff;'></iframe></form>");
隐藏的输入以另一种形式放置在 div 中,它之所以在另一种形式中的原因是因为上面的表单将嵌套在下面的表单中,如果我在上面的表单中包含隐藏的输入,那么我在使用 $_POST 时会遇到问题以嵌套形式发布隐藏输入中的值:
<form id="QandA" action="" method="post">
<div class='hiddenimg'></div>
</form>