javascript - JS如何做到瀏覽本機檔案。
欧阳克
欧阳克 2017-07-05 10:49:31
0
2
820

我知道 input type=‘file’可以做到。
但是我看一些網站是用p綁定一個事件做到的,不知道是怎麼實現的。

欧阳克
欧阳克

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

全部回覆(2)
代言

親,這個好辦,你綁定p click事件,再click 隱藏的input[file]的輸入框!

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

一個方案是,有個隱藏的input file在其它地方,點p後觸發它。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!