Safari on iOS 9 does not trigger click event on hidden input file

前提是你 提交于 2019-11-29 02:00:59

Three things are causing this problem:

  1. At javascript, removing return false; of event listener.

  2. At the stylesheet, the element which calls the action must have the property cursor: pointer;. Probably Apple put this requirement in these calls for best feedback on user interface.

  3. Again at the stylesheet, we can't setting display: none; for hidden input because some browsers don't accept clicks on elements that aren't displayed.

Link to fixed example on JSFiddle

Putting the <input type="file"/> on top of the fake button with position: absolute and opacity: 0 works. You might also need to set the correct z-index and make the input 100% width and height so it catches the click on top of the button.

Source: https://forums.meteor.com/t/webkit-on-ios-ignores-trigger-click-on-file-input/29828

Try to remove touchstart event from JS file or replace it with mousedown event.

$(document).on('click', '.upload-box', function(e){
  ...
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!