input type=file 上传图片并显示

    xiaoxiao2021-04-12  48

    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; } });
    转载请注明原文地址: https://ju.6miu.com/read-667522.html

    最新回复(0)