美文网首页
原生JS读取本地选择的文件

原生JS读取本地选择的文件

作者: 银魂飞雪 | 来源:发表于2020-07-10 16:03 被阅读0次
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      function onChange(event) {
        const file = event.target.files[0];
        console.log(event, file);
        const reader = new FileReader();
        reader.onloadend = (arg) => {
          console.log(reader.result);
        };
        reader.readAsDataURL(file);
      }
    </script>
  </head>
  <body>
    <input type="file" onchange="onChange(event)" />
  </body>
</html>

相关文章

网友评论

      本文标题:原生JS读取本地选择的文件

      本文链接:https://www.haomeiwen.com/subject/slymcktx.html