引入jq文件
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.js"></script>
js代码
<script>
$(function(){
$('#file').change(function(){
$filePath=URL.createObjectURL(this.files[0]);
$('#img').attr('src',$filePath);
})
})
</script>
html代码
<div>
<img src="" id="img" width="50px" height="50px" alt="">
<input type="file" id="file" name="file">
</div>