How to open select file dialog via js?

前端 未结 9 1670
伪装坚强ぢ
伪装坚强ぢ 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:21

    First Declare a variable to store filenames (to use them later):

    var myfiles = [];
    

    Open File Dialog

    $('#browseBtn').click(function() {
        $('').on('change', function () {
            myfiles = this.files; //save selected files to the array
            console.log(myfiles); //show them on console
        }).click();
    });
    

    i'm posting it, so it may help someone because there are no clear instructions on the internet to how to store filenames into an array!

提交回复
热议问题