<input type="text" size="4" value="100" name="fileSizeLimit" id="fileSizeLimit"/> K
<input type="file" name="file1" id="file1" size="40" onchange="changeSrc(this)"/>
<img src="about:blank" id="fileChecker" style="display:none;">
<script type="text/javascript" defer>
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;
alert((Number(oFileChecker.fileSize)/1024).toFixed(2)+"k")
if (oFileChecker.fileSize > limit)
{
alert("too large");
}
else
{
alert("ok");
}
}
</script>
posted on 2006-12-04 13:12
汪杰 阅读(779)
评论(0) 编辑 收藏 引用 所属分类:
javascript