由于项目需要!需要脚本在客户端判断大小和文件类型!自己网上找资料找的好辛苦!索性自己写了一个并测试 文件上传大小限制的一个例子,兼容ie6,ie7,ie8 ,Google Chrome,ff等浏览器 复制代码 代码如下: <BR>var isIE = /msie/i.test(navigator.userAgent) && !window.opera; <BR>function fileChange(target,id) { <BR>var fileSize = 0; <BR>var filetypes =[".jpg",".png",".rar",".txt",".zip",".doc",".ppt",".xls",".pdf",".docx",".xlsx"]; <BR>var filepath = target.value; <BR>var filemaxsize = 1024*2;//2M <BR>if(filepath){ <BR>var isnext = false; <BR>var fileend = filepath.substring(filepath.indexOf(".")); <BR>if(filetypes && filetypes.length>0){ <BR>for(var i =0; i<filetypes.length;i++){ <BR>if(filetypes[i]==fileend){ <BR>isnext = true; <BR>break; <BR>} <BR>} <BR>} <BR>if(!isnext){ <BR>alert("不接受此文件类型!"); <BR>target.value =""; <BR>return false; <BR>} <BR>}else{ <BR>return false; <BR>} <BR>if (isIE && !target.files) { <BR>var filePath = target.value; <BR>var fileSystem = new ActiveXObject("Scripting.FileSystemObject"); <BR>if(!fileSystem.FileExists(filePath)){ <BR>alert("附件不存在,请重新输入!"); <BR>return false; <BR>} <BR>var file = fileSystem.GetFile (filePath); <BR>fileSize = file.Size; <BR>} else { <BR>fileSize = target.files[0].size; <BR>} <br><br>var size = fileSize / 1024; <BR>if(size>filemaxsize){ <BR>alert("附件大小不能大于"+filemaxsize/1024+"M!"); <BR>target.value =""; <BR>return false; <BR>} <BR>if(size<=0){ <BR>alert("附件大小不能为0M!"); <BR>target.value =""; <BR>return false; <BR>} <BR>} <BR>