//监测文件大小,不允许上传超过5M的文件
function getFileSize(filePath) {
var isIE=!!window.ActiveXObject;
var isIE6=isIE && !window.XMLHttpRequest;
var isIE8=isIE && !!document.documentMode;
var isIE7=isIE && !isIE6 && !isIE8;
if (isIE){
if (isIE6){
var image = new Image();
image.dynsrc= filePath.value;
if(image.fileSize > 5242880) {
alert("上传附件大小不允许超过5M!");
clearFileInput(filePath);
return;
}
}else if (isIE8){
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(fso.GetFile(filePath.value).size > 5242880) {
alert("上传附件大小不允许超过5M!");
clearFileInput(filePath);
return;
}
}else if (isIE7){
var fso = new ActiveXObject("Scripting.FileSystemObject");
if(fso.GetFile(filePath.value).size > 5242880) {
alert("上传附件大小不允许超过5M!");
return;
}
} else {
}
}
}
function clearFileInput(file){
var form=document.createElement('form');
document.body.appendChild(form);
//记住file在旧表单中的的位置
var pos=file.nextSibling;
form.appendChild(file);
form.reset();
pos.parentNode.insertBefore(file,pos);
document.body.removeChild(form);
}
监测文件大小
最新推荐文章于 2022-07-01 13:12:36 发布