码迷,mamicode.com
首页 > 编程语言 > 详细

javascript判断上传文件大小

时间:2014-11-04 10:53:35      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   java   sp   文件   

<!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" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
</head>
<body>
    <input type="file" id="btnFile" />
</body>
</html>
<script>
    var btn = document.getElementById(‘btnFile‘);
    btn.onchange = function(){
    getSize(this);
    function getSize(t){
        var size;
        if(t.files){
            size = parseInt( t.files[0].size / 1024 /1024,10);
        }else{

            size = parseInt( new ActiveXObject("Scripting.FileSystemObject").GetFile(t.value).size / 1024/1024,10 );
        }
        if( size >= 2){
            alert(‘文件过大‘);
        }
    };
</script>

 

javascript判断上传文件大小

标签:style   blog   http   io   color   ar   java   sp   文件   

原文地址:http://www.cnblogs.com/fengzekun/p/4072798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!