由於項目需要!需要腳本在客戶端判斷大小和檔案類型!自己上網找資料找的好辛苦!索性自己寫了一個並測試檔案上傳大小限制的一個例子,相容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.FileSystemObjecting" ); <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 = getget. 0].size; <BR>} <br><br>var 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>