<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="file" id="file"/>
</body>
<script>
file.onchange = function() {
var file = this.files[0];
if(file) {
if(/(image)/g.test(file.type)) {
var reader = new FileReader(),
imgUrlBase64 = reader.readAsDataURL(file);
reader.onload = function() {
console.log(reader.result);
}
}
}
}
</script>
</html>
网友评论