<input type="file" id="fileText">
<input type="button" value="检查文件大小" onclick="checkFileChange(document.getElementById('fileText'));">
<script type="text/
javascript">
var Sys = {};
if(navigator.userAgent.indexOf("MSIE")>0)
{
Sys.ie=true;
}
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)
{
Sys.firefox=true;
}
function checkFileChange(obj)
{
var filesize = 0;
if(Sys.firefox)
{
filesize = obj.files[0].fileSize;
}else if(Sys.ie)
{
var fileobject = new ActiveXObject ("Scripting.FileSystemObject");//获取上传文件的对象
var file = fileobject.GetFile (document.getElementById("fileText").value);//获取上传的文件
var filesize = file.Size;//检测 上传文件大小
}
alert(filesize);
}
</script>