<!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>