在html中使用javascript显示本地图片的功能如下:
<html>
<head>
<script type="text/javascript">
function getFullPath(obj){
if(obj){
//ie
if (window.navigator.userAgent.indexOf("MSIE")>=1) {
obj.select();
return document.selection.createRange().text;
}
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1){
if(obj.files){
return window.URL.createObjectURL(obj.files.item(0));
}
return obj.value;
}
return obj.value;
}
}
</script>
</head>
<body>
<input type="file" onchange="document.getElementById('img').src=getFullPath(this);" />
<img id="img" />
</body>
</html>
上面的代码可直接复制到一个html文件里,运行查看结果。针对火狐的那段代码对firefox 6或以前的版本可能不适用,可改为以下的代码进行测试。
//firefox
else if(window.navigator.userAgent.indexOf("Firefox")>=1){
if(obj.files){
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
参考自:如何在界面上显示本地图片 http://blog.youkuaiyun.com/qiaomuhong/article/details/7926648
5005

被折叠的 条评论
为什么被折叠?



