,我能想到的唯一的事情就是用那些好醇” ActiveX对象:
var axFile = new ActiveXObject("Scripting.FileSystemObject");
var fileObj = axFile.getFile(document.getElementById('<%= fupAttachment.ClientID %>').value);
var fileSize = {bytes: fileObj.size,
kBytes: Math.round(fileObj.size/1024),
mBytes: Math.round((fileObj.size/1024)/1024)};
这应该提供对旧版IE的支持,完整版可能看起来像这样:
var axFile, fileSize,
fuDocument = document.getElementById('<%= fupAttachment.ClientID %>');
if (fuDocument.files)
{
fileSize = fuDocument.files[0].size || 0;//default value = 0
}
else
{
axFile = new ActiveXObject("Scripting.FileSystemObject");
fileSize = (axFile.getFile(fuDocument.value) || {size:0}).size;//default to object literal, with size: 0 property --> avoids errors, and defaults to size value of zero
}
return fileSize;//console.log, alert... whatever you want
使用IE10,IE <= 9不支持文件api – Musa
支持IE的任何其他代码? – Jd30814
@ Jd30814:我提供了一些应该支持IE的代码 - 你有没有机会测试它,如果是的话:它工作吗? –