JavaScript检测上传文件类型
很实用的一个JS代码,判断一个上传表单允许上传的文件类型,扩展性很好,只要改变数组里的扩展名就可判断你要的类型<html><head><title>JS判断上传文件类型</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><script type="text/javascript"><!-- BeginextArray = new Array(".gif", ".jpg", ".png",".txt");//允许上传的文件类型function LimitAttach(form, file) {allowSubmit = false;if (!file) return;while (file.indexOf("\\") != -1)file = file.slice(file.indexOf("\\") + 1);ext = file.slice(file.indexOf(".")).toLowerCase();for (var i = 0; i < extArray.length; i++) {if (extArray == ext) { allowSubmit = true; break;}}if (allowSubmit) form.submit();elsealert("只能上传:"+ (extArray.join("")) + "\n请重新选择文件"+ "再上传.");}//End --></script></head><body><form method=post name=upform action="" enctype="multipart/form-data"><input type=file name=uploadfile><input type=button name="Submit" value="Submit"></form></body></html>
页:
[1]