我有一个取消按钮,当用户上传文件时会出现。如果用户希望取消文件上传,那么他们可以通过单击“取消”按钮,它会向用户显示取消消息。
尝试此操作时的唯一问题是,它说明在我要显示消息的 stopImageUpload 函数中未定义 cancel_image_file_name。但我确实在 startImageUpload 函数中定义了这个。所以我的问题是如何从 startImageUpload 函数中获取 cancel_image_file_name 并在 stopImageUpload 函数中定义它?
下面是显示这两个函数的代码:
启动图像上传功能:
var cancelimagecounter = 0;
function startImageUpload(imageuploadform, imagefilename){
cancelimagecounter++;
var _cancelimagecounter = cancelimagecounter;
$('.imageCancel').on("click", function(event) {
var cancel_image_file_name = $(this).attr('cancel_image_file_name');
return stopImageUpload(2, cancel_image_file_name);
});
return true;
}
停止图像上传功能:
var imagecounter = 0;
function stopImageUpload(success, imagefilename){
var result = '';
imagecounter++;
if (success == 1){
result = '<span class="imagemsg'+imagecounter+'">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 if (success == 2){
result = '<span class="imageemsg">' + cancel_image_file_name + ' Upload Was Cancelled!</span><br/><br/>';
}
else {
result = '<span class="imageemsg">There was an error during file upload!</span><br/><br/>';
}
return true;
}