Trigger file input dialog

前端 未结 8 2061
忘了有多久
忘了有多久 2021-02-13 04:31

How can I auto trigger file input? ie. in the link below I want to trigger upload button on load

DEMO

相关标签:
8条回答
  • 2021-02-13 05:04

    The problem with your code is that you are applying a click event to the input and also to the div enclosing the button, but not to the actual button.

    if you change your fiddle to this

    <form id="test_form">
      <input type="file" id="test">
          <div id="test1"><button onclick="alert('click');">Upload</button></div>
    </form>
    

    and

    $("#test1 button").trigger('click');
    

    then the click trigger will be applied to the button. Alternatively give your button an ID and fo

    $("#buttonid").trigger('click');
    
    0 讨论(0)
  • 2021-02-13 05:08

    You can do it somthing like as :

    <button id="upld_btn">Upload</button>
    
    $(document).ready(function () {
       $('#upld_btn').trigger('click');
    });
    
    0 讨论(0)
提交回复
热议问题