<html>
<head>
</head>
<body>
上传文件<input type="file" onchange="handleChange()" />
<br>
<textarea id="previewText" style="width: 700px;height:600px;"></textarea>
<script>
function handleChange() {
const myFile = document.querySelector("input[type=file]").files[0];
const reader = new FileReader(); // 读取文件资源
if (myFile) {
reader.readAsDataURL(myFile);
}
reader.onload = function (data) {
console.log(data.target.result);
let res = data.target.result;
res = res.substring(res.indexOf('base64,') + 7);
res = window.atob(res);//base64解码
document.getElementById("previewText").value = res;
};
}
</script>
</body>
</html>
留笔记,省的再找