2015-09-25 15:29
题主
zzq
用户名称:
zzq
加入日期:
2015-08-12 11:19
登录次数:
23
image控件的src如何设置成本地的图片
我想让image控件显示本地D盘下的图片,那这个src应该怎么设置?
2015-09-25 18:11
#1
Zhao WJ
用户名称:
zhaowj
加入日期:
2011-05-02 12:07
登录次数:
2356
//一段代码供参考 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; }
2021-07-29 14:04
#2
坏孩子
用户名称:
sweethuaihaizi
加入日期:
2021-01-12 10:46
登录次数:
24
请问解决了吗?
返回
开发者社区