<script type="text/javascript">
function readAsBase64() {
var file = document.getElementById("imagefile").files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function (e) {
var result = document.getElementById("result");
console.log(this.result); //base64编码格式
// result.innerHTML='<img src="'+this.result+'" alt=""/>'
}
}
</script>
<body>
<p>
<label>请选择一个文件:</label>
<input type="file" id="imagefile" />
<br/>
<input type="button" value="读取图像" onClick="readAsBase64();" />
</p>
<div name="result" id="result">
<!-- 这里用来显示图片结果-->
</div>
</body>
标签:编码,前端,base64,result,file,reader,var From: https://www.cnblogs.com/auroraQ/p/17616717.html