zoukankan      html  css  js  c++  java
  • JS input file 转base64 JS图片预览

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>简单的html5 File测试 for pic2base64</title>
    <style>
    </style>
    <script>
        window.onload = function () {
            var input = document.getElementById("fielinput");
            var txshow = document.getElementById("txshow");
            if (typeof (FileReader) === 'undefined') {
                result.innerHTML = "抱歉,你的浏览器不支持 FileReader,请使用现代浏览器操作!";
                input.setAttribute('disabled', 'disabled');
            } else {
                input.addEventListener('change', readFile, false);
                txshow.onclick = function () { input.click(); }
            }


        }
        function readFile() {
            var file = this.files[0];
            //判断是否是图片类型
            if (!/image/w+/.test(file.type)) {
                alert("只能选择图片");
                return false;
            }
            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function (e) { txshow.src = this.result; alert(this.result); }

        
        }

    </script>
    </head>
    <body>

    <input type="file" id="fielinput" >
    <img id="txshow" style="100px;height:100px;"/>
    </body>
    </html>

  • 相关阅读:
    everything is nothing
    基础算法
    OC 优化目录
    iOS 更改启动视图
    单例--iOS
    OC-Objection 学习笔记之一:简单的开始
    iOS 类库列表
    IOS 上线问题
    OC强弱引用的使用规则
    设置桌面图标
  • 原文地址:https://www.cnblogs.com/tiancai/p/5619621.html
Copyright © 2011-2022 走看看