FileReader遇到Image,,,,,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>createObjectURL</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<input type="file" id="file-list">
<script>
function createObjectURL(bolb){//创建
return window[window.webkitURL ? 'webkitURL':'url']['createObjectURL'](bolb);
}
function revokeObjectURL(bolb) {//占用了内存,释放
return window[window.webkitURL ? 'webkitURL' : 'url']['revokeObjectURL'](bolb);
}
var filesList=document.getElementById('file-list');
filesList.onchange=function(evnt){
let files=event.target.files,
reader=new FileReader(),
url=createObjectURL(files[0]);
if(url){
if(/image/.test(files[0].type)){
var img=new Image();
img.src=url;
document.body.appendChild(img);
}
}
revokeObjectURL(files[0]);
}
</script>
</body>
</html>
共同学习,写下你的评论
评论加载中...
作者其他优质文章