图片上传预览

来源:互联网 发布:在线考试管理系统php 编辑:程序博客网 时间:2024/06/10 17:53
<div class="form-group">            <label for="img">图片</label>            <input type="file" id="upload" name="img" class="" id="img"  >        </div>        <div class="form-group" style="display: block">            <img src="" alt="" class="img-rounded" id="pic" style="width: 140px;height: 140px;">        </div> $(function(){        $("#upload").on("change",function(){            var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径,该路径不是图片在本地的路径            if (objUrl) {                $("#pic").attr("src", objUrl) ;            }        });    });    function getObjectURL(file) {        var url = null ;        if (window.createObjectURL!=undefined) { // basic            url = window.createObjectURL(file) ;        } else if (window.URL!=undefined) { // mozilla(firefox)            url = window.URL.createObjectURL(file) ;        } else if (window.webkitURL!=undefined) { // webkit or chrome            url = window.webkitURL.createObjectURL(file) ;        }        return url ;    }
原创粉丝点击