如何使用jQuery在弹出窗口中预览选定的输入类型为“文件”的图片?

8 浏览
0 Comments

如何使用jQuery在弹出窗口中预览选定的输入类型为“文件”的图片?

这个问题已经在这里得到了答案

在上传之前预览图像

在我的代码中,我允许用户上传图像。现在我想在同一个弹出窗口中显示此选定的图像作为预览。我如何使用jQuery来实现它?

以下是我在弹出窗口中使用的输入类型。

HTML代码:


admin 更改状态以发布 2023年5月22日
0
0 Comments

如果您正在使用HTML5,可以尝试以下代码片段




0
0 Comments

演示

HTML:

your image

jQuery

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function (e) {
            $('#blah').attr('src', e.target.result);
        }
        reader.readAsDataURL(input.files[0]);
    }
}
$("#imgInp").change(function(){
    readURL(this);
});

参考资料

0