javascript - How to browse local files in JS.
欧阳克
欧阳克 2017-07-05 10:49:31
0
2
849

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.

欧阳克
欧阳克

温故而知新,可以为师矣。 博客:www.ouyangke.com

reply all(2)
代言

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>
为情所困

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template