new FileReader()

FileReader图片转成base64格式二进制编码


<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

</head>

<body>

    <img src="./img/Home.png" />

    <input type="file" class="upload" />

</body>

<script>

    document.querySelector(".upload").onchange = function(){

        console.log(this.files[0]);

        let fileReader = new FileReader();

        fileReader.readAsDataURL(this.files[0]);

        fileReader.onload = function(){

            console.log(fileReader.result);

        }

    }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-01-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案