1. 程式人生 > >使用blob來做上傳圖片預覽

使用blob來做上傳圖片預覽

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<script type="text/javascript" src="jquery-1.11.3.min.js"></script>
<div>
 <img style="width: 200px;height:200px;border-radius: 100%"  src="https://img2018.cnblogs.com/blog/1195302/201811/1195302-20181128163006342-890300325.jpg"/>
</div>


<input type="file"  id="input"/ >
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">

$("input").change(function(){

	var files = document.getElementById('input').files  


	$("img").attr("src", window.URL.createObjectURL(files[0]));

});

</script>
</body>
</html>