<html>
<head>
<script type="text/javascript">
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
function fileChange(target) {
var fileSize = 0;
if (isIE && !target.files) {
var filePath = target.value;
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
var file = fileSystem.GetFile (filePath);
fileSize = file.Size;
alert(fileSize);
} else {
fileSize = target.files[0].size;
console.log(fileSize);
}
var size = fileSize / 1024;
if(size>1000){
document.getElementById("upfileSubmit").disabled=true;
alert("附件不能大于1M,请重新选择!");
}
else
{
document.getElementById("upfileSubmit").disabled=false;
}
}
</script>
</head>
<body>
<form name="form" method="post" action="" enctype="multipart/form-data" >
<input type="file" name="filename" size="20" onchange="fileChange(this);">
<input type="submit" value="上传" name="Send" id="upfileSubmit">
</form>
</body>
</html>