我有一个在 jQueryUI 模式对话框中启动的 PLUpload。在对话框中启动后,PlUpload 的拖放功能仍然有效,但单击启动文件浏览器则无效。
以下代码的 JsFiddle。JsFiddle 包括我的应用程序正在使用的 jQuery 和 jQuery UI 版本:http: //jsfiddle.net/QqPLV/1/
HTML:
<a href="#" id="add-file-link">Open Uploader As Dialog</a>
<div id="AddFilePopup" title="Add A File">
<div id="drop-target">After opening in a dialog clicking here does nothing, but drag and drop in Chrome still works...</div>
<div id="plupload-nohtml5">No runtime found, your browser doesn't support HTML5 drag & drop upload.</div>
<div id="plupload-filelist"></div>
</div>
CSS:
#drop-target {
border: 3px dashed #CCC;
text-align: center;
color: #999;
font-size: 16px;
padding : 50px;
cursor: pointer;
}
#debug {
margin-top: 20px;
}
#plupload-debug {
border : 1px Solid #600;
padding : 5px;
margin : 5px;
}
Javascript:
$(function () {
$('#add-file-link').click(function () {
$('#AddFilePopup').dialog({
modal: true,
width: 600
});
uploader.refresh(); //this fixes IE10 not being able to click to add files
return false;
});
initPlUpload();
});
function initPlUpload() {
uploader = new plupload.Uploader({
runtimes: 'html5',
drop_element: 'drop-target',
browse_button: 'drop-target',
max_file_size: '4mb',
upload: "upload.php"
});
uploader.bind('Init', function (up, params) {
if (uploader.features.dragdrop) {
$('#plupload-nohtml5').hide();
};
});
uploader.bind('FilesAdded', function (up, files) {
for (var i in files) {
$('#plupload-filelist').append('<div id="' + files[i].id + '">- ' + files[i].name + ' - ' + files[i].id + ' (' + plupload.formatSize(files[i].size) + ')</div>');
}
});
uploader.init();
}
我添加了行
uploader.refresh();
到点击处理程序,并修复了 IE10,但 Chrome 仍然拒绝合作。甚至输入 uploader.refresh(); 进入 Chrome 的控制台并不能恢复上传者的浏览功能......
编辑:删除一些不需要重现问题并使其更难阅读的行。