Input File Click Chrome

后端 未结 2 1961
名媛妹妹
名媛妹妹 2021-02-20 03:32

Ok so I have an input element of type file and id \"test\"

When I put in the address bar: javascript: document.getElementById(\"test\").click() it brings up the open fil

相关标签:
2条回答
  • 2021-02-20 04:02

    I had the same problem and managed to solve it(though I am using jQuery). I detailed the technique in another question

    Jquery trigger file input

    The idea was essentially to focus the file input before triggering the click programatically.

    0 讨论(0)
  • 2021-02-20 04:22

    You should wrap file-input element to other (ex.:div): HTTM:

    <div>
    <input type='file'>
    <div>
    

    CSS:

    div{
    height:1px;
    overflow: hidden;
    }
    

    JS:

    $('div input').click();
    

    Good luck...

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