我在一个项目上使用 blueimp 文件上传插件,但在使用 IE8 时遇到了一些困难,主要是什么都没发生!
我的设置尽可能接近插件演示设置 - 文件包含在相同的顺序中,html 结构变化很小,css 是相同的等等。
在其他浏览器 + ie9 中,一切都按预期工作,但在 ie8 中,添加图像的按钮好像没有附加任何内容。
如果我在 ie9 中上传,然后使用开发工具将文档类型切换为 ie8,则可以成功从服务器检索图像。
我很难显示完整的代码,因为不幸的是文档非常复杂,但是页面位于此处: http ://www.yoursplash.co.uk/index.php?route=product/product&product_id=108
这几乎是与文件上传相关的所有内容:
这些是我为了让插件工作而包含的文件
<script src="http://blueimp.github.com/JavaScript-Templates/tmpl.min.js"></script>
<script src="http://blueimp.github.com/JavaScript-Load-Image/load-image.min.js"></script>
<script src="http://blueimp.github.com/JavaScript-Canvas-to-Blob/canvas-to-blob.min.js"></script>
<script src="catalog/view/javascript/jquery/blueimp/jquery.iframe-transport.js"></script>
<script src="catalog/view/javascript/jquery/blueimp/jquery.fileupload.js"></script>
<script src="catalog/view/javascript/jquery/blueimp/jquery.fileupload-fp.js"></script>
<script src="catalog/view/javascript/jquery/blueimp/jquery.fileupload-ui.js"></script>
<script src="catalog/view/javascript/jquery/blueimp/jquery.fileupload-jui.js"></script>
这是我自己的插件实现
'use strict';
$(document).on('ready', function () {
$.ajax({
url: '/index.php?route=product/userimage&usetype=get',
dataType: 'json',
context: $('#fileupload')[0]
}).done(function (result) {
$(this).fileupload('option', 'done').call(this, null, {result: result});
if ($('#filesContainer > .template-download').length > 0)
{
$('a[href="#user-upload"]').removeClass('selected').siblings('a[href="#user-photos"]').addClass('selected');
$('#user-upload').hide().siblings('#user-photos').fadeIn();
};
});
});
$('#fileupload').fileupload(
{
url: '/index.php?route=product/userimage&usetype=put',
type: 'POST',
maxFileSize: 5000000,
fileInput : '#imgUp',
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
process: [
{
action: 'load',
fileTypes: /^image\/(gif|jpeg|png)$/,
maxFileSize: 5000000 // 20MB
}
],
filesContainer: '#filesContainer'
})
.bind('fileuploadadded', function (e, data)
{
$('a[href="#user-upload"]').removeClass('selected').siblings('a[href="#user-photos"]').addClass('selected');
$('#user-upload').hide().siblings('#user-photos').fadeIn();
})
.bind('fileuploadcompleted', function (e, data)
{
return $('#filesContainer .uploadedImage').draggable({ containment : 'document', revert : true, appendTo : 'body', helper: function(e,ui){ return $('<img/>',{ src : $(e.target).data('src')}).css('width','150px'); } }).tooltip({ tooltipClass : 'image-gallery-tooltip' , position : { at: 'bottom center'} });
});
这是我实现插件的 HTML
<form id="fileupload" action="//jquery-file-upload.appspot.com/" method="POST" enctype="multipart/form-data">
<!-- Redirect browsers with JavaScript disabled to the origin page -->
<noscript><input type="hidden" name="redirect" value="http://blueimp.github.com/jQuery-File-Upload/"></noscript>
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row fileupload-buttonbar">
<div class="span7" style="height:30px;">
<p style="float:left;display:block;width:480px;margin-right:10px;padding:5px;">Select images from your computer and once uploaded you may use them in your design</p>
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="btn btn-success fileinput-button">
<i class="icon-plus icon-white"></i>
<span>Add images..</span>
<input type="file" name="files[]" id="imgUp" multipart>
</span>
</div>
<!-- The global progress information -->
<div class="span5 fileupload-progress fade">
<!-- The global progress bar -->
<div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="bar" style="width:0%;"></div>
</div>
<!-- The extended global progress information -->
<div class="progress-extended"> </div>
</div>
</div>
<!-- The loading indicator is shown during file processing -->
<div class="fileupload-loading"></div>
</form>
任何帮助都会得到很大的帮助——我差点用这个把头发扯掉,因为似乎没有什么好的理由让它不起作用!