<input type="file" name="noticeFileName" style="width: 400px;" onchange="fileChange(this);" />
<script type="text/javascript">
function fileChange(target) {
var filetypes = [".zip", ".ZIP",".pdf",".PDF"];
var filepath = target.value;
if (filepath) {
var isnext = false;
var fileend = filepath.substring(filepath.lastIndexOf("."));
if (filetypes && filetypes.length > 0) {
for (var i = 0; i < filetypes.length; i++) {
if (filetypes[i] == fileend) {
isnext = true;//allowed file
break;
}
}
}
if (!isnext) {
alert("不接受此文件类型!");
target.value = "";
return false;
}
} else {
return false;
}
var filemaxsize = 1024 * 1024*5;
var fileSize = target.files[0].size;
if (fileSize > filemaxsize) {
alert("附件大小不能大于" + (filemaxsize /1024/1024)+ "MB!");
target.value = "";
return false;
}
if (fileSize <= 0) {
alert("附件大小不能为0M!");
target.value = "";
return false;
}
}
</script>
|