日期:2014-05-16  浏览次数:20314 次

javascript 监测(控制 )上传文件大小
<script language="javascript">
var oForm = new Object();
var oImage = new Image();
oImage.attachEvent('onload',getSize);
oImage.attachEvent('onerror',doWithError);
function checkImage(obj){
    oForm = obj;
    oImage.src = oForm.oFile.value;
}
function getSize(){
    var oImgSize = Math.floor(oImage.fileSize/1024);
    if(oImgSize>200){
        window.alert('不允许上传大于200KB的图片!');
        oForm.reset();
    }
}
function doWithError(){
    window.alert('出现错误:请重新选择图片上传!');
    oForm.reset();
}
</script>
?
<form name="data_form" method="post" enctype="multipart/form-data"> 
   <input type="file" name="oFile" onpropertychange="javascript:checkImage(document.data_form);">
</form>
?