How to open select file dialog via js?

前端 未结 9 1803
伪装坚强ぢ
伪装坚强ぢ 2021-01-30 06:16
$(\'#id\').click();

It doesn\'t work on Chrome 26 on Mac OS.

The problem actually is creation "upload" widget that can be integrated in

9条回答
  •  独厮守ぢ
    2021-01-30 07:09

    Using jQuery

    I would create a button and an invisible input like so:

    
    
    

    and add some jQuery to trigger it:

    $('#button').on('click', function() {
        $('#file-input').trigger('click');
    });
    

    Using Vanilla JS

    Same idea, without jQuery (credits to @Pascale):

    
    
    

提交回复
热议问题