12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <button onclick="files()">加载文件</button>
- <script>
- async function files() {
- const options = {
- types: [
- {
- description: '这只是一个描述',
- accept: {
- 'image/*': ['.png', '.gif', '.jpeg', '.jpg'],
- "text/plain": [".txt"],
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': ['.xlsx']
- }
- }
- ],
- excludeAcceptAllOption: false // 有一个选项的按钮
- // multiple: true
- }
- console.log("--")
- try {
- const file = await window.showOpenFilePicker(options)
- // const file = await window.showSaveFilePicker(options)
- // const file = await window.showDirectoryPicker(options)
- console.log(file)
- } catch (error) {
- console.error(error)
- }
- }
- </script>
- </body>
- </html>
|