html5 实现客户端验证上传文件的大小(简单实例)

2019-01-28 14:53:32于海丽
  •         for (var i = 0, f; f = files[i]; i++)               {      
  •             //检查文件的类型是否符合指定要求                   if(jQuery.inArray(f.type , mimes) == -1)      
  •             {                       alert('File type '+ f.type + ' not allowed');      
  •                 $(this).val('');                       continue;      
  •             }              
  •             //检查文件大小                   else if(f.size > max_size)      
  •             {                       alert('Maximum file size is ' + max_size + ' bytes.');      
  •                 $(this).val('');                   }      
  •                     //Validation ok      
  •             else                  {      
  •                 output.push('[b]', f.name, '[/b] (', f.type || 'n/a', ') - ', f.size, ' bytes, last modified: ', f.lastModifiedDate.toLocaleDateString() );                   }