js获取本地即将上传文件的大小 [兼容IE、FF、chrome]
js获取本地即将上传文件的大小:
<input type="file" onchange="fileChange(this);" /> <script type="text/javascript"> var isIE = /msie/i.test(navigator.userAgent) && !window.opera; function fileChange(target) { var fileSize = 0; if (isIE && !target.files) { var filePath = target.value; var fileSystem = new ActiveXObject("Scripting.FileSystemObject"); var file = fileSystem.GetFile (filePath); fileSize = file.Size; } else { fileSize = target.files[0].size; } var size = fileSize / 1024; alert('文件大小: '+size+'KB'); } </script>