Posted on 2008-04-15 18:07
G_G 阅读(1596)
评论(0) 编辑 收藏 所属分类:
javascript
js 上
限制:<input type="text" size="4" value="10" name="fileSizeLimit" id="fileSizeLimit"/> K
<input type="file" name="file1" id="file1" size="40" onchange="changeSrc(this)"/>
<br>
<img src=http://blog.xunuo.com/blog/images/icons/23.gif id="fileChecker" alt="test"/>
<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>
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);
alert( (f.size/(1024*1024))+" Bytes");
}
//-->
</script>
</html>