js 读取本地图片

JavaScript 2017-11-06

js 读取本地图片 并取得base64 数据:
<h3>获取图片</h3>
<input type="file" value="选择图片" data-clear-btn="true" name="file-2" id="imgOne" onchange="preImg(this.id,'imgPre');">

<input type="text" data-clear-btn="true" id="datatxt"></input>

<script>
function preImg(sourceId, targetId) {

    if (typeof FileReader === 'undefined') {
        alert('Your browser does not support FileReader...');
        return;
    }
    var reader = new FileReader();
    reader.onload = function(e) {
        var img = document.getElementById_x_x_x(targetId);
        img.src = this.result;
        var data = this.result;
        $("#datatxt").val(data.substr(23));
       // alert("dddd:"+this.result);
    }
  reader.readAsDataURL(document.getElementById_x_x_x(sourceId).files[0]);

}
</script>


本文由 伯仁 创作,采用 知识共享署名 3.0,可自由转载、引用,但需署名作者且注明文章出处。

4 条评论

  1. viagra pills

    viagra vs viagra levitra gstbk_add.php?sid= - nebenwirkung viagra - nebenwirkungen viagra 5mg t[...]

  2. tadalafil 5mg

    cialis vs viagra forum joyfulyy.cgi - cheap generic cialis - cialis information levitra ascendi[...]

  3. cialis coupon

    buy cialis online username - genuine viagra cialis gel tabs best price buy online - levitra cia[...]

  4. viagra for sale

    viagra online profile - viagra online without prescription - generic viagra, effects

添加新评论