在<head></head>之前写入以下Javascript代码:
1 <script language=javascript>
2 //上传4张图片,分别是4张图片的大小
3 var FileSize = new Array(0, 0, 0, 0);
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
2 //上传4张图片,分别是4张图片的大小
3 var FileSize = new Array(0, 0, 0, 0);
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)">
<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的大小来控制大小了。