通过打开<input type =“file”/>将照片插入<img/>

时间:2016-02-28 13:45:46

标签: javascript jquery html

请告诉我,当我打开时,如何将照片插入for j,i in enumerate(files): if name in i: print i fn,_,sn = i.rpartition(name) os.rename(os.path.join(path, i), os.path.join(path, fn+sn)) files[j] = fn+sn for j,i in enumerate(dir): if name in i: print i fn,_,sn = i.rpartition(name) os.rename(os.path.join(path, i), os.path.join(path, fn+sn)) dir[j] = fn+sn <img>并选择任何文件? 我如何使用JS / JQuery?

1 个答案:

答案 0 :(得分:0)

使用&#39; FileReader&#39;对象:

$("#yourinput").change(function () {
    var file = this.files[0];
    var reader = new FileReader();
    reader.onload = function (e) {
        $("#yourimg").attr("src", e.target.result);
    }
    reader.readAsDataURL(file);
});