在前端判断<input type="file" />的大小,
在IE下使用了ActiveObject(弊端:需要客户点击运行控件)
在Chrome下使用了fileObj.files[0].size(这个方法可行,但是还不知道什么原理,有待考究)
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>js判断上传文件大小</title>
</head>
<body>
<input type="file" id="fileId" />
<input type="button" value="IE下使用" onclick="showSizeInIE()"/>
<input type="button" value="Chrome下使用" onclick="showSizeInChrome()" />
</body>
<script type="text/javascript">
function showSizeInIE()
{
var fileObj = document.getElementById("fileId");
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.getFile(fileObj.value);
alert(f.size + " bytes");
}
function showSizeInChrome()
{
var fileObj = document.getElementById("fileId");
alert(fileObj.files[0].size + " bytes");
}
</script>
</html>