function readURL(input) {
if (input.files && input.files[0]) { //Revisamos que el input tenga contenido
var reader = new FileReader(); //Leemos el contenido
reader.onload = function(e) { //Al cargar el contenido lo pasamos como atributo de la imagen de arriba
$('#blah').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function() { //Cuando el input cambie (se cargue un nuevo archivo) se va a ejecutar de nuevo el cambio de imagen y se verá reflejado.
readURL(this);
});
虽然这个问题的表述有点糟糕,但我给你留下了你提问的答案。添加一个标签就足够了
img
,我们将在加载后随图像的内容进行更改,为此我们将使用JQuery,但也可以使用Pure JS来完成。