简体   繁体   中英

Why does my file input only accept one file?

I have the following Razor markup with a file input that I want to be able to select multiple files with:

<form asp-action="Upload">
    <input type="file" name="file" id="file" multiple onchange="javascript: updateFileList();" />
    <br />Selected files:
    <div id="fileList"></div>
    <div class="form-group">
        <input id="submitButton" type="submit" value="Upload" class="btn btn-default" />
        <a asp-action="Explorer" class="btn btn-default">Cancel</a>
    </div>
</form>

Yet each time I select one file, the input's value changed to only that file, ie it only lets me select one file at a time.

For the curious, the updateFileList function looks like this:

function updateFileList() {
    var input = document.getElementById('file');
    var output = document.getElementById('fileList');
    output.innerHTML = '<ul>';
    for (var i = 0; i < input.files.length; ++i) {
        output.innerHTML += '<li>' + input.files.item(i).name + '</li>';
    }
    output.innerHTML += '</ul>';
}

What is wrong here?

检查您的updateFileList()函数是否可以正常工作

<input type="file" name="file" id="file" multiple onchange="javascript: updateFileList();" />

The problem is I was trying to select file after file by clicking the Choose Files button once for each file. If I click it only once and select multiple files in the file selection dialogue, it works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM