可以在html5中validationinput = file的大小和types

我正在阅读这个http://dev.w3.org/html5/markup/input.file.html ,但我只find了“接受”属性。

我试过这个

<input type="file" name="imagefilename" accept="image/x-png, image/gif, image/jpeg" /> 

是否有可能在文件大小的客户端validation?

我发现这个技术的IE浏览器

 <html> <head> <script> function getSize() { var myFSO = new ActiveXObject("Scripting.FileSystemObject"); var filepath = document.upload.file.value; var thefile = myFSO.getFile(filepath); var size = thefile.size; alert(size + " bytes"); } </script> </head> <body> <form name="upload"> <input type="file" name="file"> <input type="button" value="Size?" onClick="getSize();"> </form> </body> </html> 

是否有可能使用html5文件系统API来做同样的事情?

UPDATE

我可以做这个( 演示 ):

 <!doctype html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> </head> <body> <form > <input type=file id=f max-size=32154 > <input type=submit> </form> <script> $(function(){ $('form').submit(function(){ var isOk = true; $('input[type=file][max-size]').each(function(){ if(typeof this.files[0] !== 'undefined'){ var maxSize = parseInt($(this).attr('max-size'),10), size = this.files[0].fileSize; isOk = maxSize > size; return isOk; } }); return isOk; }); }); </script> </body> 

它工作正常,但我认为这将是更好的本地html5 attrvalidation

  <form class="upload-form"> <input class="upload-file" data-max-size="2048" type="file" > <input type=submit> </form> <script> $(function(){ var fileInput = $('.upload-file'); var maxSize = fileInput.data('max-size'); $('.upload-form').submit(function(e){ if(fileInput.get(0).files.length){ var fileSize = fileInput.get(0).files[0].size; // in bytes if(fileSize>maxSize){ alert('file size is more then' + maxSize + ' bytes'); return false; }else{ alert('file size is correct- '+fileSize+' bytes'); } }else{ alert('choose file, please'); return false; } }); }); </script> 

http://jsfiddle.net/9bhcB/2/

我可以做这个( 演示 ):

 <!doctype html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script> </head> <body> <form > <input type=file id=f max-size=32154 > <input type=submit> </form> <script> $(function(){ $('form').submit(function(){ var isOk = true; $('input[type=file][max-size]').each(function(){ if(typeof this.files[0] !== 'undefined'){ var maxSize = parseInt($(this).attr('max-size'),10), size = this.files[0].fileSize; isOk = maxSize > size; return isOk; } }); return isOk; }); }); </script> </body>