js上傳圖片擷取圖片地址,相容蘋果

來源:互聯網
上載者:User

標籤:

別人寫的一個例子我記下了先,自己測試通過的 是別人分享的頁面,原作者我是不知道了,感謝原作者寫的代碼下面是代碼:全部複製就是例子  <!DOCTYPE html><html>     <head>        <meta charset="UTF-8">        <title></title>        <script src="//cdn.bootcss.com/jquery/1.8.3/jquery.js"></script>        <style type="text/css">            li {                width: 100px;                height: 100px;                float: left;                border: 1px solid red;            }        </style>    </head>     <body>    <input type="file" name="" id="files-list" value="" />    <div id=‘output‘>     </div>    <div id="progress">     </div></body></html><script type="text/javascript"> var filesList=document.getElementById("files-list");    filesList.onchange=function(ev){        var info="",            output=document.getElementById("output"),            progress=document.getElementById("progress"),            files=ev.srcElement.files,            type=‘default‘,            reader=new FileReader();            if(/image/.test(files[0].type)){                                reader.readAsDataURL(files[0]);                                console.log(files[0]);                type=‘image‘            }else{ //                reader.readAsText(files[0]);//                type=‘text‘;//                        console.log(‘請輸入圖片類型‘)            }             reader.onerror=function(){                output.innerHTML="失敗"+reader.error.code;            };            reader.onprogress=function(ev){                 if(ev.lengthComputable){                    progress.innerHTML=ev.loaded+‘/‘+ev.total;                    console.log(progress.innerHTML)                }             };            reader.onload=function(){                            var html=‘‘;                console.log(reader)                switch(type){                    case ‘image‘ :                    html="<img src=\""+reader.result+"\">";                    break;                    case ‘text‘:                    html=reader.result;                    break                 }                output.innerHTML=html;            }            } </script>

js上傳圖片擷取圖片地址,相容蘋果

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.