codeUpFile.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <button onclick="files()">加载文件</button>
  11. <script>
  12. async function files() {
  13. const options = {
  14. types: [
  15. {
  16. description: '这只是一个描述',
  17. accept: {
  18. 'image/*': ['.png', '.gif', '.jpeg', '.jpg'],
  19. "text/plain": [".txt"],
  20. 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': ['.xlsx']
  21. }
  22. }
  23. ],
  24. excludeAcceptAllOption: false // 有一个选项的按钮
  25. // multiple: true
  26. }
  27. console.log("--")
  28. try {
  29. const file = await window.showOpenFilePicker(options)
  30. // const file = await window.showSaveFilePicker(options)
  31. // const file = await window.showDirectoryPicker(options)
  32. console.log(file)
  33. } catch (error) {
  34. console.error(error)
  35. }
  36. }
  37. </script>
  38. </body>
  39. </html>