zoukankan      html  css  js  c++  java
  • 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=" 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=" 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>
  • 相关阅读:
    软件工程作业03
    PSP0级要求02
    PSP0级要求日志
    软件工程个人作业02
    第三周学习进度
    第二周学习进度
    软件工程个人作业01
    Web网页登录设计
    第一周学习进度
    第三周学习进度条+PSP0过程文档
  • 原文地址:https://www.cnblogs.com/wangshuai6707/p/4383082.html
Copyright © 2011-2022 走看看