效果

在这里插入图片描述

示例

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <!-- When the multiple Boolean attribute is specified, the file input allows the user to select more than one file. -->
        <input type="file" multiple="true" />

        <script type="text/javascript">
            window.onload = function(event) {
                main();
            }
            
            function main() {
                const inputFile = document.querySelector('input[type=file]');
                inputFile.onchange = InputFile_onChange;
            }
            
            function InputFile_onChange(event) {
                // console.log(event);
                const files = event.target.files;
                console.log(files);
            }
        </script>
    </body>
</html>

参考

HTML > Elements > input > input type=“file” - multiple

更多推荐