input预览上传图片

html代码html

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

 

 

js代码web

    $("#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);
        })
相关文章
相关标签/搜索