open file upload dialog on click

前端 未结 3 1143
旧时难觅i
旧时难觅i 2021-01-07 18:00

I have to open file upload dialog by clicking some other button i.e i am hiding file upload control(visibility:hidden) and on clicking of some other button i want to open th

相关标签:
3条回答
  • 2021-01-07 18:21

    You should position input[file] just above your custom control. And then bind to it`s onclick.

    Also make in it bigger font-size, as only this way you can increase it's height.

    0 讨论(0)
  • 2021-01-07 18:35

    In your example, your file input did not have an id, yet you are trying to reference it with #input. This works for me:

    $('#button').click(function() {
        $('input[type=file]').click();
    });
    
    0 讨论(0)
  • 2021-01-07 18:36

    Tested today the simple code given in the question and the situation has changed:

    • IE9: works
    • Chrome23: works
    • Firefox15: works

    There is just one catch - on IE the .click() is a blocking operation while on other browsers it is not.

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