本文實例為大家分享了jQuery上傳圖片顯示預覽的具體代碼,供大家參考,具體內容如下
<!DOCTYPE html> <html> <head> <title>HTML5上傳圖片預覽</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="http://img9.tongzhuo100.com/js/jquery-1.7.2.min.js"></script> <style> .hide { display:none; } </style> </head> <body> <h4>請選擇圖片文件:JPG/GIF</h4> <form name="form0" id="form0" > <input type="file" name="file0" id="file0" multiple="multiple" /> <br><br><img src="" id="img0" width="120" class="hide"> </form> <script> $("#file0").change(function(){ var objUrl = getObjectURL(this.files[0]) ; console.log("objUrl = "+objUrl) ; if (objUrl) { $("#img0").attr("src", objUrl); $("#img0").removeClass("hide"); } }) ; //建立一個可存取到該file的url 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 ; } </script> </body> </html>
另外有需要云服務器可以了解下創(chuàng)新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
名稱欄目:簡單實現jQuery上傳圖片顯示預覽功能-創(chuàng)新互聯
文章網址:http://aaarwkj.com/article40/ccjpho.html
成都網站建設公司_創(chuàng)新互聯,為您提供定制開發(fā)、用戶體驗、云服務器、自適應網站、網站改版、App設計
聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯