本地图片转base64

∥☆過路亽.° 提交于 2019-12-30 16:47:38

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function ToBase64() {
/*转换base64*/
var img = document.getElementById('upload')
var imgFile = new FileReader();
imgFile.readAsDataURL(img.files[0]);

imgFile.onload = function () {
var imgData = this.result; //base64数据
console.log(imgData);
}

}
</script>
<input type="file" name="" id="upload">
<button onclick="ToBase64()">to base64</button>
</body>
</html>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!