當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JavaScript读取本地图片到浏览器
生活随笔
收集整理的這篇文章主要介紹了
JavaScript读取本地图片到浏览器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼:
<html> <head> <script type="text/javascript"> function getFileUrl(sourceId) { var url; if (navigator.userAgent.indexOf("MSIE")>=1) { // IE url = document.getElementById(sourceId).value; } else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)); } else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)); } return url; }function preImg(sourceId, targetId) { var url = getFileUrl(sourceId); var imgPre = document.getElementById(targetId); imgPre.src = url; } </script> </head> <body> <input type="file" name="imgOne" id="imgOne1"總結
以上是生活随笔為你收集整理的JavaScript读取本地图片到浏览器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NPOI 将DataGridView导出
- 下一篇: Entity Framework Cod