search

Home  >  Q&A  >  body text

javascript - The file selection pop-up window cannot be called up in the callback function

HTML

<input id="videoInput" type="file" style="display: none" />
<button type="submit" id="videoUploadInput">上传文件</button>

JS

$('#videoUploadInput').click(function (e) {
  e.preventDefault()
  setTimeout(function() {
     document.getElementById('videoInput').click()
  }, 2000)
})

The initial positioning reason is that the click event is triggered by the callback function. At this time, event.isTrusted is false (this attribute is currently only supported in IE and Firefox), rather than being actively triggered by the user, that is, this event is not Trusted by the browser.

给我你的怀抱给我你的怀抱2831 days ago689

reply all(2)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-19 10:41:48

    http://stackoverflow.com/ques...

    http://stackoverflow.com/ques...

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-19 10:41:48

    1. Change the delayed 2000 to 1000

    Link description

    2. Delayed processing functions are executed immediately

    setTimeout((function(){})(),2000)

    reply
    0
  • Cancelreply