///验证单个文件不能超过30M function onChangeFile() { ///定义布尔类型的返回结果,初始值为false(默认不超过30M) var sResult = false; ///获得并计算附件大小 var fso = new ActiveXObject("Scripting.FileSystemObject"); var fileObj = fso.GetFile(AttachForm.upFile.value); var filesize = (fileObj.size/1024)/1024; ///验证附件大小是否超过30M if(filesize.toFixed(2) > 30) { alert('文件大小不能超过30M!'); sResult = true; } return sResult; }