javascript - filereader shim,无法让它在 ie9 中工作

标签 javascript jquery filereader

有人设法从 https://github.com/aFarkas/webshim/ 获取文件读取器填充程序吗?在 IE9 中工作。

event.target.files 未定义,我无法获取有关所选文件的任何信息?

我有

$('#fp_file').on('change',function() {
    fileSelected( $(this) );
}); 

// File selected
function fileSelected(ele)
{    

var file = $(ele).prop('files')[0];  

var fileSize = 0;  

if(file)
{
  if(file.size > 1024 * 1024)
  {
      fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
  }
  else
  {
      fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
  }

  $('#fileName').html(file.name);
  $('#fileSize').html(fileSize);
  $('#fileType').html(file.type);
  $('#file_dets').show('slide');

}
else
{
  alert('no file : ' + file);
}

}

以及以下 HTML...

<!DOCTYPE html>
<html>
<head>
<title>Financial Promotions Form</title>
<link rel="stylesheet" type="text/css" href="financial_promotion.css" />
<script src="jquery-1.7.1.min.js" type="text/javascript"></script>          
<script src="js-webshim/minified/extras/modernizr-custom.js" type="text/javascript"></script> 
<script src="js-webshim/minified/polyfiller.js" type="text/javascript"></script>       

</head>
<body>

<div id="wrapper">

<form id="financial_promotion" action="financial_promotions.pl" method="post" enctype="multipart/form-data">               
            <fieldset>
                <legend>Promotion Documentation&nbsp;</legend>
                    <label for="fp_file">Upload File</label>

                    <input class="ws-filereader" type="file" name="fp_file" id="fp_file" />

            </fieldset> 
            <fieldset id="file_dets">
                <legend>File Information</legend>
                <div>
                    <label for="fileName">Name</label><span id="fileName"></span>
                </div>
                <div>
                    <label for="fileSize">Size</label><span id="fileSize"></span>
                </div>
                <div>
                    <label for="fileType">Type</label><span id="fileType"></span>
                </div>
            </fieldset>                                
   </form>        
   </div>

   </body>
    </html>

但是,我无法访问已选择的文件,如果我使用 $(ele).prop('files')[0];event.target.files 或任何其他组合,它在 IE9 中始终未定义?

最佳答案

呸,骗子!

GITHUB 上的示例注释掉了使其工作的部分!!!

//webshims.setOptions('basePath', '/js-webshim/minified/shims/');

我在文档中看到了这一点,并错误地认为它是说 - 请参阅此设置 - 不要使用它! - 这就是注释掉的代码的本质。

我所需要的只是正确设置基本路径并且它可以工作。

webshims.setOptions({
    'basePath':'/my/folder/path/js-webshim/minified/shims/'
    });

webshims.polyfill('forms forms-ext filereader');

希望它能帮助所有我见过的像我一样的帖子的其他人,OP已经没有头发了!

----> 更新 2014 年 5 月 27 日 <----

我相信这种聚丝/垫片不起作用。一旦你在 IE9 中运行它,你会发现 flash 对象会覆盖输入元素,因此当选择文件时,底层输入元素不会填充所选文件,因此无法将表单提交为输入为空。

关于javascript - filereader shim,无法让它在 ie9 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23786073/

相关文章:

java - Base64字符串到字节数组的转换

javascript - 使用带有像素的背景位置的中心图像

javascript - IndexedDB:将文件存储为 File 或 Blob 或 ArrayBuffer。什么是最好的选择?

jquery - 如何通过 jquery 更改按钮的位置和页面高度?

javascript - 用背景颜色智能地填充 Bootstrap 列

javascript - jQuery 定位需要 &lt;!DOCTYPE HTML>

javascript - 如何给js和css文件添加版本号

javascript - 如何从 Dropzone 的投递箱区域中删除文件?

javascript - BreezeJS 中央错误处理程序和自动重试

javascript - 从回调中调用 javascript 对象方法