注: http://www.java114.com/277/content4355.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> upload </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <FORM ACTION="load.jsp" METHOD="POST" ENCTYPE="mutipart/form-data" name="myform"> 请选择上传文件:<INPUT TYPE="file" NAME="picture"/> <INPUT TYPE="button" value="提 交" οnclick="check(myform);"/> <INPUT TYPE="button" value="取 消" οnclick="window.close();"/> </FORM> </BODY> </HTML> <mce:script language="javascript"><!-- function isEmpty(str){ for(var i=0;i<str.length;i++){ if(str.charAt(i)!==" "){ return false; } } return true; } function check(form){ var fileName = form.picture.value; if(isEmpty(fileName)){ alert("请选择文件名"); form.picture.focus(); return false; } //lastIndexOf如果没有搜索到则返回为-1 if(fileName.lastIndexOf(".")!=-1) { var fileType = (fileName.substring(fileName.lastIndexOf(".")+1,fileName.length)).toLowerCase(); var suppotFile = new Array(); suppotFile[0] = "gif"; suppotFile[1] = "bmp"; suppotFile[2] = "jpg"; for(var i =0;i<suppotFile.length;i++){ if(suppotFile[i]==fileType){ return true; }else{ continue; } } alert("不支持文件类型"+fileType); return false; }else { alert("文件只支持JIF,BMP,JPG"); } } // --></mce:script>