2010-07-27 35 views
1

我有文件上傳程序中的取消按鈕錯誤。取消按鈕不起作用,如果我試圖刪除(取消)添加更多的文件按鈕。Asp.Net MVC中的Javascript多文件上傳錯誤:取消按鈕不起作用

這裏是javascript代碼:

<script type="text/javascript"> 
    function addFileUploadBox() { 
     if (!document.getElementById || !document.createElement) 
      return false; 

     /*********************Gets the previous upload area *******************************/ 

     var uploadArea = document.getElementById("file_region"); 
     if (!uploadArea) 
      return; 
     var newLine = document.createElement("br"); 
     uploadArea.appendChild(newLine); 

     /********** Creating the input type of file***************************/ 

     var newUploadBox = document.createElement("input"); 
     // Set up the new input for file uploads 
     newUploadBox.type = "file"; 
     newUploadBox.size = "20"; 
     // The new box needs a name and an ID 
     if (!addFileUploadBox.lastAssignedId) 
      addFileUploadBox.lastAssignedId = 100; 
     newUploadBox.setAttribute("id", "dynamic" + addFileUploadBox.lastAssignedId); 
     newUploadBox.setAttribute("name", "dynamic:" + addFileUploadBox.lastAssignedId); 

     var cancelBtn = document.createElement("input"); 
     cancelBtn.setAttribute("type", "button"); 
     cancelBtn.setAttribute("name", "btnCancel"); 
     cancelBtn.setAttribute("value", "Cancel"); 
     cancelBtn.setAttribute("id", "cancel" + addFileUploadBox.lastAssignedId); 
     // cancelBtn.setAttribute("onclick", alert(addFileUploadBox.lastAssignedId)); 
     uploadArea.appendChild(newUploadBox); 
     uploadArea.appendChild(cancelBtn); 
     addFileUploadBox.lastAssignedId++; 


     /*************Creating the input type of button***************************/ 
    } 

這裏是查看網頁文件上傳代碼:

  <p id="file_region"> 
      <input type="file" id="file" name="file" /> 
      <input type="button" id="cancel" value="Cancel" /> 
    <input type="button" id="more_file" value="Attach more files" onclick="addFileUploadBox();" />  

///////////// ////////////////////////////////////////////////// /////

回答