input预览上传图片

Posted 小盆友灬

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了input预览上传图片相关的知识,希望对你有一定的参考价值。

html代码

<input type="file" name="file"  id="file" >
<img src=""  id="img">

 

 

js代码

    $("#file").bind("change",function(){
            var url = null;
            if(window.createObjectURL != undefined) {
                url = window.createObjectURL(this.files[0]);
            } else if(window.URL != undefined) {
                url = window.URL.createObjectURL(this.files[0]);
            } else if(window.webkitURL != undefined) {
                url = window.webkitURL.createObjectURL(this.files[0]);
            }
            $("#img").attr("src",url);
        })

 

以上是关于input预览上传图片的主要内容,如果未能解决你的问题,请参考以下文章