js实现”选择文件“和”选择文件夹“功能

212 阅读1分钟
<body>
  <button>选择文件夹</button>
  <input type="file">
  <script>
    let button = document.querySelector('button')
    button.onclick = async function () {
      try {
        const file = await showDirectoryPicker()
        console.log(file, "file");
      } catch {

      }
    }
  </script>
</body>