input 上传图片转base64
作者:互联网
input 上传的图片转base64
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
</head>
<body>
<ul>
<li>
上传视频:<input type="file" class="video">
</li>
</ul>
<button>Send</button>
<script>
let params = new FormData();
$('.video').on('change', function( e ){
//e.currentTarget.files 是一个数组,如果支持多个文件,则需要遍历
params.append('filesrc', e.currentTarget.files[0])
var reader = new FileReader()
reader.readAsDataURL( e.currentTarget.files[0])
// 获取base64
reader.onload = function() {
console.log('输出base64',reader.result)
}
});
</script>
</body>
</html>
标签:files,base64,params,currentTarget,reader,input,上传 来源: https://www.cnblogs.com/Ananiah/p/14664079.html