jQuery实现input file选择图片后可预览图片的效果

jQuery实现input file选择图片后,可以预览图片的效果,选中后即显示查看。

JSP:

    <div>
        <img src="" id="img">
    </div>
    <label >
        点击这里添加图像
        <input type="file" id="file" style="display: none">
    </label>

JQuery

$("#img").change(function(){
    $("#file").attr("src",URL.createObjectURL($(this)[0].files[0]));
});
原文地址:https://www.cnblogs.com/lumc5/p/15708941.html