一、JavaScript/jQuery部分
$('#photo').bind('change',function(){
var file=$("#photo").get(0).files[0];//得到file对象
var srcValue=window.URL.createObjectURL(file);//传入的参数创建一个指向该参数对象的URL
$("#my-photo").attr('src',srcValue);
});
二、html部分
<img id="my-photo">
<input id="photo" name="photo" type="file" required accept=".jpg,.jpeg,.png" />
结语:到此,上传到页面的图片就可以回显在当前页面指定容器上了。