大佬教程收集整理的这篇文章主要介绍了jQuery AJAX Fileupload交叉浏览器支持,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我正在使用的基本HTML:
<form > <input type="file" name="FileFields" id="FileFields"/> <button type="button" onclick="uploadFile();" id="uploadButton">Upload</button> <ul id="files"/> ... other form elements ... </form> <div id="fileUploadDiv"/>
这是uploadFile函数:
function uploadFile() { //we don't want more then 5 files uploaded if($('#files li').size() >= 5) { return; } //disable the upload button $('#uploadButton').attr('disabled','disabled'); //show loading animation $('#files').append( $('<li>') .attr('id','loading') .append( $('<img>').attr('src','/images/loading.gif') ) .addClass('loading') ); //add all neccessary elements (the form and the iframE) $('#fileUploadDiv').append( $('<form action="/uploadFile" method="post" id="fileUploadForm">') .attr('enctype','multipart/form-data') .attr('encoding','multipart/form-data') .attr('target','upload_frame') .append( $('#FileFields').clone() .css('visibility','hidden') ) .append( $('<iframe>').attr('name','upload_frame') .load(function(){finishedPosTingFile();}) .attr('id','upload_frame') .attr('src','') .css({ 'width':'0px','height':'0px','border':'0px none #fff' }) ) ); //start uploading the file $('#fileUploadForm').submit(); }
iframe完成发布/加载后,finishedPosTingFile()将成为回调函数.
现在,这就像Firefox中的魅力,但在IE中不起作用.我已经发现IE需要attr(‘encoding’,…)而不是attr(‘enctype’,…)而且我也尝试过它而不是通过将这些元素写成普通的html来动态创建表单和iframe,这并没有真正有所作为.
IE(IE8,具体而言,尚未在< 8中测试过)没有出错,加载动画只是继续旋转,没有文件被上传......
任何人都知道如何使这项工作?
以上是大佬教程为你收集整理的jQuery AJAX Fileupload交叉浏览器支持全部内容,希望文章能够帮你解决jQuery AJAX Fileupload交叉浏览器支持所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。