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

参见英文答案 > Preview an image before it is uploaded16个答案在我的代码中,我允许用户上传图像。现在我想显示这个选择的图像作为预览在同一个弹出。我如何使用jQuery做它?

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

HTML代码

<input type="file" name="uploadNewImage">

解决方法

Demo

HTML:

<form id="form1" runat="server">
   <input type='file' id="imgInp" />
   <img id="blah" src="#" alt="your image" />
</form>

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);
});

Reference

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...