在过去的5个小时里,我一直试图弄明白这一点。
我尝试了无数的在线发现的方法,但没有一种方法可行。到目前为止,这种方法效果最好(只显示一个错误)。
我得到的错误是:“未捕获的ReferenceError:未定义deletefile” 请注意,仅当我单击“删除”超链接时才会出现错误。
//UPLOAD CODE
$(document).ready(function() {
// Custom example logic
function $(id) {
return document.getElementById(id);
}
var uploader = new plupload.Uploader({
runtimes : 'gears,html5,flash,silverlight,browserplus',
browse_button : 'pickfiles',
container: 'container',
drop_element: 'uploadBox',
max_file_size : '10mb',
url : 'upload.php',
flash_swf_url : '../js/plupload/plupload.flash.swf',
silverlight_xap_url : '../js/plupload/plupload.silverlight.xap',
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
]
//,
//multipart_params : {
// "title" : $("#title").val(),
// "descripition" : $("#description").val()
//}
});
uploader.bind('Init', function(up, params) {
if (uploader.features.dragdrop) {
var target = $("uploadBox");
target.ondragover = function(event) {
event.dataTransfer.dropEffect = "move";
this.className = "dragover";
};
target.ondragenter = function() {
this.className = "dragover";
};
target.ondragleave = function() {
this.className = "";
};
target.ondrop = function() {
this.className = "";
};
}
});
uploader.bind('FilesAdded', function(up, files) {
function deletefile(i) {
uploader.splice(i,1);
}
for (var i in files) {
$('filelist').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <a href="#" onclick="deletefile(\'' + i + '\');">Remove</a><b></b></div>';
}
});
uploader.bind('UploadProgress', function(up, file) {
$(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
});
$('uploadfiles').onclick = function() {
uploader.start();
return false;
};
uploader.init();
});
感谢。
答案 0 :(得分:3)
假设filelist
是一个ID(因此,使用$('#filelist')
),您可以尝试替换它:
uploader.bind('FilesAdded', function(up, files) {
function deletefile(i) {
uploader.splice(i,1);
}
for (var i in files) {
$('filelist').innerHTML += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <a href="#" onclick="deletefile(\'' + i + '\');">Remove</a><b></b></div>';
}
});
用这个:
uploader.bind('FilesAdded', function(up, files) {
var deleteHandle = function(uploaderObject, fileObject) {
return function(event) {
event.preventDefault();
uploaderObject.removeFile(fileObject);
$(this).closest("div#" + fileObject.id).remove();
};
};
for (var i in files) {
$('#filelist').append($('<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <a href="#" id="deleteFile' + files[i].id + '">Remove</a></div>'));
$('#deleteFile' + files[i].id).click(deleteHandle(up, files[i]));
}
});
我还假设$('uploadfiles')
应该是$('#uploadfiles')
,但这超出了问题的范围。
希望这会有所帮助。
答案 1 :(得分:0)
// jquery plugin
uploader.plupload('getUploader').splice();
$('.plupload_filelist_content', uploader).empty();
答案 2 :(得分:0)
uploader=newplupload.Uploader({
//-----
});
uploader.bind('FilesAdded',function(up,files)
{
//----
up.refresh();//RepositionFlash/Silverlight
});
uploader.bind('QueueChanged',function(up,files){
//#doc-filelist is the id of dive, which shows the Queue
$('#doc-filelist').html('');
$.each(uploader.files,function(i,file){
$('#doc-filelist').append(
'<divid="'+file.id+'">'+
file.name+'('+plupload.formatSize(file.size)+')<b></b>'+
'<spanclass="remove_file"data-file="'+i+'">X</span>'+
'</div>');
});
if(uploader.files.length==0){
$('#uploadfiles').addClass('disabled');
}
//console.log(uploader.files);
});
uploader.bind('UploadComplete', function (up, file) {
up.splice();
up.refresh();
});
$('.relevant-document').on('click','.remove_file',function(e){
uploader.splice($(this).attr('data-file'),1);
uploader.refresh();
});