liyongli 3 роки тому
батько
коміт
cf9ebf5192
1 змінених файлів з 43 додано та 0 видалено
  1. 43 0
      codeUpFile.html

+ 43 - 0
codeUpFile.html

@@ -0,0 +1,43 @@
+<!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>