From 609f7d41acbc7266cc3864169cd779df8251be71 Mon Sep 17 00:00:00 2001 From: itorr Date: Mon, 15 Aug 2022 23:02:24 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=AE=9A=E4=BB=85=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=9B=BE=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/document.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/html/document.js b/html/document.js index 973c17b..06121d3 100644 --- a/html/document.js +++ b/html/document.js @@ -187,18 +187,20 @@ const data = { }; +const chooseFileForm = document.createElement('form'); +const chooseFileInput = document.createElement('input'); +chooseFileInput.type = 'file'; +chooseFileInput.accept = 'image/*'; +chooseFileForm.appendChild(chooseFileInput); + const chooseFile = callback=>{ - chooseFile.form.reset(); - chooseFile.input.onchange = function(){ + chooseFileForm.reset(); + chooseFileInput.onchange = function(){ if(!this.files||!this.files[0])return; callback(this.files[0]); }; - chooseFile.input.click(); + chooseFileInput.click(); }; -chooseFile.form = document.createElement('form'); -chooseFile.input = document.createElement('input'); -chooseFile.input.type = 'file'; -chooseFile.form.appendChild(chooseFile.input); const init= _=>{