<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> </head> <body> <input type="file" id="btnFile" /> </body> </html> <script> var btn = document.getElementById('btnFile'); btn.onchange = function(){ getSize(this); function getSize(t){ var size; if(t.files){ size = parseInt( t.files[0].size / 1024 /1024,10); }else{ size = parseInt( new ActiveXObject("Scripting.FileSystemObject").GetFile(t.value).size / 1024/1024,10 ); } if( size >= 2){ alert('文件过大'); } }; </script>