Asp.Net MVC中的Javascript多文件上传器错误:取消按钮不起作用

时间:2010-07-27 10:32:41

标签: javascript asp.net ajax asp.net-mvc asp.net-mvc-2

我在文件上传器中的CANCEL按钮出错。如果我试图删除(取消)添加更多文件按钮,则取消按钮不起作用。

这是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***************************/
    }

这是View页面文件上传代码:

          <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();" />    

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

1 个答案:

答案 0 :(得分:0)

我已经使用这个jQuery插件一次上传多个文件,并认为它很棒:http://www.fyneworks.com/jquery/multiple-file-upload/