How to detect multiple files selection with touch screen on mobile devices

╄→尐↘猪︶ㄣ 提交于 2019-12-11 10:53:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!