问题
I need to count the number of selected files during a multiple selection by clicking on a input type="file"
element of a form. I'm writing the code on my laptop and everything is working fine with this code:
function counter() {
var inputUploader = document.querySelector('input[type="file"]'),
chosenFiles = inputUploader.files,
filesCount = chosenFiles.length > 1 ? chosenFiles.length : chosenFiles.length;
alert(filesCount);
}
<form>
<div>
<input id="inputUploader" type="file" name="x" multiple />
</div>
</form>
<button onclick="counter()">click</button>
But trying to test the code on a mobile device (demo), I incontered the bug: if I execute the code from a mobile device, the multiple selection turns out to be ONE (number), while from the computer no... There seems to be a different trigger between the (multiple) selection made with the mouse and the one made with the touch on a mobile device.
Cheers and thank you
#Edit:
I also noticed that, if you visit the demo from the VIA mobile browser (https://play.google.com/store/apps/details?id=mark.via.gp), the multiple selection is not available, while if you browse from Firefox mobile it is possible, but as mentioned the selection seems to be UNIQUE
来源:https://stackoverflow.com/questions/56476753/how-to-detect-multiple-files-selection-with-touch-screen-on-mobile-devices