zoukankan      html  css  js  c++  java
  • 上传图片时获取所传图片大小

      在<head></head>之前写入以下Javascript代码:

     1        <script language=javascript>
     2        //上传4张图片,分别是4张图片的大小
     3        var FileSize = new Array(0000);
     4        //当前选择框的索引
     5        var FileIndex = 0;
     6        //选择文件后显示到Img中
     7        function ChangeSrc(hifilObj, Index)
     8        {
     9            document.all.imgBeforeUpload.src = hifilObj.value;
    10            FileIndex = Index;
    11        }

    12        //获得图片信息
    13        function GetSize()
    14        {
    15            FileSize[FileIndex] = document.all.imgBeforeUpload.fileSize;
    16        }

    17        //清零
    18        function SetSizeZero()
    19        {
    20            if(document.all.imgBeforeUpload.src == "")
    21                FileSize[FileIndex] = 0;
    22        }

    23        </script>
    24

      在<html></html>间定义一个Img:
    <img src="" id="imgBeforeUpload" onreadystatechange="GetSize()" onpropertychange="SetSizeZero()" style="DISPLAY:none">

      及4个文件选择控件:
    <INPUT class="text" type="file" id="hifil0" runat="server" onpropertychange="ChangeSrc(this, 0)">
    <INPUT class="text" type="file" id="hifil1" runat="server" onpropertychange="ChangeSrc(this, 1)">
    <INPUT class="text" type="file" id="hifil2" runat="server" onpropertychange="ChangeSrc(this, 2)">
    <INPUT class="text" type="file" id="hifil3" runat="server" onpropertychange="ChangeSrc(this, 3)">

      然后就可以在提交表单之前来判断FileSize的大小来控制大小了。
  • 相关阅读:
    js 判断多个一样的name
    VisualSVN Server的配置和使用方法 图文
    file get contents 访问不了域名原因
    js confirm函数 删除提示
    关于PHP的curl开启问题
    重置svn地址
    google 火狐 模拟显示手机页面插件
    开启Apache mod_rewrite模块完全解答
    zend studio 9.0.4 破解、汉化和字体颜色及快捷键相关设置
    zend studio 8 修字体和大小
  • 原文地址:https://www.cnblogs.com/faib/p/661947.html
Copyright © 2011-2022 走看看