本文實例講述了jQuery實現的上傳圖片本地預覽效果。分享給大家供大家參考,具體如下:
<!DOCTYPE html><html><head><meta charset="UTF-8"><title>www.49028c.com jquery上傳圖片本地預覽效果</title></head><body><script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script><input id="upload" type="file"><img id="preview" src=""><script type="text/javascript">$('#upload').change(function(){ // 獲取FileList的第一個元素 alert(document.getElementById('upload').files[0]); var f = document.getElementById('upload').files[0]; src = window.URL.createObjectURL(f); document.getElementById('preview').src = src})</script></body></html>
運行效果:
更多關于jQuery相關內容感興趣的讀者可查看本站專題:《jQuery圖片操作技巧大全》、《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常用插件及用法總結》、《jQuery常見經典特效匯總》及《jquery選擇器用法總結》
希望本文所述對大家jQuery程序設計有所幫助。
新聞熱點
疑難解答