为什么“HTML 文件选择"更改所选文件的顺序并按字母顺序排序? [英] why does "HTML file select" changes the order of selected files and sort them alphabetically?
问题描述
我正在尝试获取由 HTML 中的文件"输入选择的文件的名称:
I am trying to get the name of the files that are selected by a "file" input in HTML:
<input type="file" class="filestyle" name="file-select[]" id="file-select" accept="image/*" multiple>
我为此编写了这段 JavaScript 代码:
I wrote this JavaScript code to do that:
$('#file-select').on("change", function(){
var selectedFiless = this.files;
for (var i = 0; i < selectedFiless.length; ++i) {
var name = selectedFiless.item(i).name;
alert(name);
}
});
但是,我注意到名称是按字母顺序排列的,而不是按选择顺序排列的.例如,如果我选择 z.jpg 和 a.jpg,当我打印名称时,我有 a.jpg、z.jpg(字母顺序).但我想要z.jpg, a.jpg(选择顺序).
However, I noticed that the names are sorted in alphabetical order, not in selection order. for example, if I select z.jpg and then a.jpg, when I print the names, I have a.jpg, z.jpg (alphabetical order). but I want z.jpg, a.jpg (selection order).
推荐答案
它会根据您在系统中排序
的方式出现.我的意思是,如果您在系统中设置了 Sort by 升序,那么无论您选择的顺序或顺序,它将按升序选择,反之亦然.我已经在你的 code
中进行了测试,结果正如我上面提到的.
It'll appear based on how you have sorted
in your system. I mean if you have set Sort by ascending in your system then irrespective or order you select, it will be selected in ascending order and vice versa for descending. I have tested in your code
and the results are as I have mentioned above.
演示可在您的本地系统中进行测试.
A Demo to test in your local systems.
这篇关于为什么“HTML 文件选择"更改所选文件的顺序并按字母顺序排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!