验证HTML5中input = file的大小?
您可以尝试运行以下代码来验证输入类型文件的大小:
<!DOCTYPE html> <html> <head> <script src="http://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> </head> <body> <form > <input type="file" id="myfile" data-max-size="32154" /> <input type="submit"/> </form> <script> $(function(){ $('form').submit(function(){ var val = true; $('input[type=file][data-max-size]').each(function(){ if(typeof this.files[0] !== 'undefined'){ var max = parseInt($(this).attr('max-size'),10), mySize = this.files[0].size; val = max > mySize; return val; } }); return val; }); }); </script> </body> </html>