<html>
<head>
<title>JS判断上传文件类型_www.jb200.com</title>
<SCRIPT LANGUAGE="
javascript">
<!-- Begin
extArray = new Array(".gif", ".jpg", ".png");
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[i] == ext) { allowSubmit = true;
break; }
}
if (allowSubmit) form.submit();
else
alert("只能上传: "
+ (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" onclick="LimitAttach(this.form, this.form.uploadfile.value)">
</form>
</body>
</html>