<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档 </title> </head> <body >
<script></script>
<input type='file' onchange='document.getElementById("tp").src=this.value;'>
<img id='tp' style='width:300px; height:400px'>
</body>
</html>
index.html文件
里面有一个c:/Documents and Settings/Administrator/桌面/logo22.gif'只有双击打开才可以正常现实。如果你用http://localhost这种就不行了。
经测试 ,用http://localhost 一样可以 没有问题同样可以预览 至于你的不能预览 我就不清楚了
<br/>
<input type="submit" value="确定">
<div id="targetDiv"></div>下面是js:
function checkpic(pic){
if(pic!=null){
var _strlen=pic.length;
var _pictype=pic.substr(_strlen-3).toLowerCase();
if(_pictype=="jpg" || _pictype=="gif" || _pictype=="bmp"){
bOk = true;
var Preview = document.getElementById("targetDiv");
Preview.innerHTML="";
Preview.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = pic;
Preview.style.width = "100px";
Preview.style.height = "100px";
}else{
alert('请确保上传得是图片!');
bOk = false;
}
}
}
IE6下:C:\Documents and Settings\administrator\桌面\pic.jpg
火狐下:file:///C:/Documents%20and%20Settings/administrator/%E6%A1%8C%E9%9D%A2/pic.jpg
IE7:没条件测试IE有时候显示不了好像是由于路径中的中文造成的
<body>
<script type="text/javascript">function Preview(imgFile)
{
document.getElementById("pic").filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value;}
</script><input type="file" onchange="javascript:Preview(this);" /><br />
<div id="pic" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale);width:400px;height:200px;"></div>
</body>
</html>