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

后端 未结 3 1671
感动是毒
感动是毒 2020-12-16 02:20

I have a website with an upload field, but the input is hidden with display: none; and I have a div for calling this action.

I

相关标签:
3条回答
  • Three things are causing this problem:

    1. At javascript, removing return false; of the 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 a user interface.

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

    Link to a fixed example on JSFiddle

    0 讨论(0)
  • 2020-12-16 02:59

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

    $(document).on('click', '.upload-box', function(e){
      ...
    });

    0 讨论(0)
  • 2020-12-16 03:02

    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

    0 讨论(0)
提交回复
热议问题