asp.net 用jquery判断fileupload上传文件的大小和类型和名字

 1 <script language="javascript" type="text/javascript">
 2     //检查上传文件大小和获取文件名
 3         function fileChange(target) {
 4          
 5             var fileSize = 0;
 6            
 7             var filePath = target.value;
 8            
 9             var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
10             var file = fileSystem.GetFile(filePath);
11             fileSize = file.Size;
12           
13             
14             var size = fileSize / 1024;
15             if (size > 10000) {
16                 alert("附件不能大于10M");
17             }
18             var arr = filePath.split("\\");
19             if (target.id == "FileUpload1") {
20                 document.getElementById(Label8).innerHTML = size+"KB";
21               
22               
23                 $("#Label9").html(showDate()); LinkButton1
24                 $("#LinkButton1").html(arr[arr.length - 1]);
25             } else {
26                 document.getElementById(Label10).innerHTML = size+"KB";
27 
28                 $("#Label11").html(showDate());
29                 $("#LinkButton2").html(arr[arr.length - 1]);
30             }
31 
32         }
33 </script>
 1 <tr id="trrow6"  runat="server">
 2             <td colspan="4" style="background-color: #C0C0C0">
 3                 <asp:Label runat="server" Text="上传附件" Width="301px"></asp:Label>
 4             </td>
 5         </tr>
 6          
 7         <tr>
 8             <td class="left" style="width: 167px">
 9                 附件1:
10             </td>
11             <td>
12                 <asp:FileUpload ID="FileUpload1" onchange="fileChange(this)" runat="server" Width="181px" style="display:none"/>
13                  <input id="Button3" type="button" value="上传附件" onclick="document.getElementById(‘FileUpload1‘).click();" />
14 
15                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="download"
16                         Text=‘‘ onclick="LinkButton1_Click"></asp:LinkButton>
17                 <asp:Label ID="Label14" runat="server" Text="" Visible="false"></asp:Label>
18             </td>
19             <td><asp:Label ID="Label8" runat="server" ></asp:Label></td>
20             <td><asp:Label ID="Label9" runat="server" ></asp:Label></td>
21            </tr>
22             <tr>
23             <td class="left" style="width: 167px">
24                 附件2:
25             </td>
26             <td >
27 
28                 <asp:FileUpload ID="FileUpload2" runat="server" 
29                     onchange="fileChange(this)" Width="179px" 
30                     style="display:none" 
31                      />
32                  <input id="Button2" type="button" value="上传附件"  onclick="document.getElementById(‘FileUpload2‘).click();" />
33                <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="false" CommandName="download"
34                         Text=‘‘ onclick="LinkButton1_Click"></asp:LinkButton>
35                 <asp:Label ID="Label26" runat="server" Text="" Visible="true"></asp:Label>
36                 <a title="test" ></a>
37             </td>
38             <td><asp:Label ID="Label10" runat="server"  ></asp:Label></td>
39             <td><asp:Label ID="Label11" runat="server" ></asp:Label></td>
40         </tr>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。