<script type="text/javascript">
        var rowIndex=1;
        function addImage()     //增加行
        {
            rowIndex++;
            var tb =document.getElementById("tabl");
            var tr = tb.insertRow();  
            var td1 = tr.insertCell();
            var td2 = tr.insertCell();
            var td3 = tr.insertCell();
            //td1.innerHTML = '<asp:FileUpload ID="FileUpload2" runat="server" />';
            //td1.innerHTML = '<input id="File'+rowIndex+'" type="file" />'; 
            td2.innerText="";
            td3.innerHTML='<a onclick="removeImage(this)" href="#">移除</a>';
        }
           </script>
<a onclick="addImage()" href="#">增加图片</a>
        <table id="tabl" border="0" class="perview">
            <tr>
                <td>
                    选择文件
                </td>
                <td width="50%">
                    预览图
                </td>
                <td style="text-align: center;">
                    操作
                </td>
            </tr>
            <tr>
                <td>
                    <%--<input id="File1" type="file" />
                    <br />--%>
                    <asp:FileUpload ID="FileUpload1" runat="server" />
                </td>
                <td style="text-align: center;">
                    &nbsp;</td>
                <td style="text-align: center;">
                    <a onclick="removeImage(this)" href="#">移除</a>
                </td>
            </tr>
        </table>
执行总是提示说“FileUpload'+rowIndex+'”不是有效标识符。

可是我用HTML里面的File就可以那样写
到底是哪里错了?

解决方案 »

  1.   

    ASP:FILEUPLOAD 这样的控件好像是不行!
      

  2.   


     <script language="JavaScript">
         var fileCount = 0;
         function addFile() {
             if (fileCount == 4) {
                 alert("限制上传5个文件!");
                 return;
             }
             var str = "<br /><INPUT type='file' size='50' id="+fileCount+" NAME='File' onchange=showImg(this)><br /><label id='lbl"+fileCount+"' style='font-size:14px'/>"
             document.getElementById('MyFile').insertAdjacentHTML("beforeEnd", str);
             fileCount++;
         } </script>  <input type="button" value="增加" onclick="addFile()"> 
                      <input onclick="this.form.reset()" type="button" value="重置"> 
      

  3.   

    这样不行的话
    那多文件上传用><INPUT type="file"怎么上传?
      

  4.   

    <script type="text/javascript"> 
    function AddFile() 

      var strFile=" <input name=\"upload_file\" type='file' class='inputText' style='WIDTH:350px;'/> <br/>"; 
      document.getElementById("td_uploadFile").insertAdjacentHTML("beforeEnd",strFile); 

        </script> 
      <input id="BtnAddFile" type="button" class="inputButton" value="增加附件" onclick="javascript:AddFile()" /> <td id="td_uploadFile" align="center"> 
      <input id="upload_file" name="upload_Attachment" type="file" class="inputText" 
          style="width: 350px; display:none;" runat="server" /> 
    </td> 
    HttpFileCollection Files = HttpContext.Current.Request.Files; 
                for (int i = 0; i < Files.Count; i++) 
                {                 HttpPostedFile PostedFile = Files[i]; 
                    if (PostedFile.ContentLength > 0) 
                    {} 
              } 
      

  5.   

     protected void Btn_Upload_Click(object sender, EventArgs e)
        {
            string filepath = Server.MapPath(@"~/Upload")+"\\";
            HttpFileCollection uploadfile = Request.Files;
            for (int i = 0; i < uploadfile.Count; i++)
            {
                HttpPostedFile postedfile = uploadfile[i];
                try
                {
                    if (postedfile.ContentLength > 0)
                    {
                        Label1.Text = "文件 #" + (i + 1) + ":" + System.IO.Path.GetFileName(postedfile.FileName) + "〈br/>";
                        postedfile.SaveAs(filepath + System.IO.Path.GetFileName(postedfile.FileName));  
                    }
                }
                catch (Exception Ex)
                {
                    Label1.Text += "发生错误: " + Ex.Message;
                }  
            }
        }
    我后台代码就是这样执行的
    可是执行后没反应啊
    那个文件夹里面也是空空的
      

  6.   

    服务器控件必须由服务器端控制你用javascript是在客户端是无法动态生成 服务器控件的.既然 input type=file可用,那就用这个吧.