input type=file 上传图片并显示

来源:互联网 发布:淘宝网能买到处方药吗 编辑:程序博客网 时间:2024/05/29 15:08
html代码:
<input type="file" name="choose" id="choose" accept="image/*"><label for="choose"><img alt="正面" id="Img" src="../../images/camera.png"> </label><p>正面</p>
js代码
$('#choose').change(function(){  $('p').css('display','none');  var objUrl = getObjectURL(this.files[0]) ;  if (objUrl) {            $('#Img').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;}});
0 0