文章详情页
javascript - JS如何做到浏览本地文件。
浏览:129日期:2023-03-19 14:04:33
问题描述
我知道 input type=‘file’可以做到。但是我看一些网站是用p绑定一个事件做到的,不知道是怎么实现的。
问题解答
回答1:亲,这个好办,你绑定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 type='file' style='display: none'></body></html>回答2:
一个方案是,有个隐藏的input file在其它地方,点p后触发它。
标签:
JavaScript
相关文章:
排行榜
