search

Home  >  Q&A  >  body text

javascript - How to browse local files in JS.

I know input type=‘file’ can do it.
But I saw that some websites use p to bind an event, and I don’t know how to implement it.

欧阳克欧阳克2702 days ago850

reply all(2)I'll reply

  • 代言

    代言2017-07-05 10:51:31

    Dear, this is easy to do, you bind the p click event, and then click the hidden input[file] input box!

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Demo</title>
        <script>
            function showResurce() {
                document.getElementById('resurce').click();
            }
        </script>
    </head>
    <body>
    <p onclick="showResurce()">点我</p>
    <input id="resurce" type="file" style="display: none">
    </body>
    </html>

    reply
    0
  • 为情所困

    为情所困2017-07-05 10:51:31

    One solution is to have a hidden input file somewhere else and trigger it after clicking p.

    reply
    0
  • Cancelreply