js判断上传文件大小:
第一种方法是利用IE控件 <html>
<input type="file" name="file1" onchange="ShowSize(this.value)">
<script language="JavaScript">
<!--
function ShowSize(files)
{
var fso,f;
fso=new ActiveXObject("Scripting.FileSystemObject");
f=fso.GetFile(files);
if(f.size>1024*4){
alert(f.size+" Bytes");
}
}
//-->
</script>
</html>
第二种方法是利用IE下,Image对象的属性,如:fileCreatedDate、fileModifiedDate、fileSize、fileUpdatedDate、filters限制:<input type="text" size="4" value="10" name="fileSizeLimit" id="fileSizeLimit"/> K
<input type="file" name="file1" id="file1" size="40" onchange="changeSrc(this)"/>
<img src="about:blank" id="fileChecker" alt="test" height="18"/><script type="text/javascript">
var oFileChecker = document.getElementById("fileChecker");function changeSrc(filePicker)
{
oFileChecker.src = filePicker.value;
}oFileChecker.onreadystatechange = function ()
{
if (oFileChecker.readyState == "complete")
{
checkSize();
}
}function checkSize()
{
var limit = document.getElementById("fileSizeLimit").value * 1024; if (oFileChecker.fileSize > limit)
{
alert("too large");
}
else
{
alert("ok");
}
}
</script>
/// <summary>