多文件(图片)上传限制上传个数,修改上传

这里是修改的时候

前台


<script language="JavaScript">
    
var i  =0;
    
var n=<%=_n %>;
    
function addFileControl()
    {
        
     
if(i<(9-n))
     {
     
var str = '<INPUT type="file" NAME="File"><br/>'
     document.getElementById(
'FileCollection').insertAdjacentHTML("beforeEnd",str)
     i
++;
     }
else
     {
         alert(
'最多只能上传10个,还剩'+(10-n)+'个可上传!')
     }
    }
    
</script>

以下是body内
<table border="0" cellpadding="0" cellspacing="0" width="100%">
        
<tr>
            
<td align="center" style=" 227px; height: 25px">
                上传新图片
            
</td>
            
<td style="height: 25px" width="72%">
                
<input onclick="addFileControl()" type="button" value="增加上传" />
                
<div id="FileCollection">
                    
<input id="File1" runat="server" name="File" type="file" /><br />
                
</div>
            
</td>
        
</tr>
        
<tr>
            
<td align="center" style=" 227px; height: 25px">
                图片说明
            
</td>
            
<td style="height: 25px">
                
<asp:TextBox ID="txtTPSM" runat="server" MaxLength="25"></asp:TextBox>
            
</td>
        
</tr>
        
<tr style="color: #000000">
            
<td height="25" style=" 227px">
            
</td>
            
<td height="25">
                
<asp:Button ID="btnAdd" runat="server" Text="上传" OnClick="btnAdd_Click" />
            
</td>
        
</tr>
    
</table>

后台代码

定义 public int _n;-----n从数据读取已经添加了几条数据,如果是添加页面就不用n参数,去掉直接用数字

上传代码主要代码

Code
原文地址:https://www.cnblogs.com/sendling/p/1423486.html