<?xml version="1.0" encoding="gb2312"?><!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>本地图片预览代码(支持 IE6、IE7)</title> <script type="text/javascript" language="javascript">...<!--function PreviewImg(imgFile)...{ //原来的预览代码,不支持 IE7。 var oldPreview = document.getElementById("oldPreview"); oldPreview.innerHTML = "<img src="file://" + imgFile.value + "" width="80" height="60" />"; //新的预览代码,支持 IE6、IE7。 var newPreview = document.getElementById("newPreview"); var imgDiv = document.createElement("div"); document.body.appendChild(imgDiv); imgDiv.style.width = "118px"; imgDiv.style.height = "127px"; imgDiv.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = scale)"; imgDiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value; newPreview.appendChild(imgDiv); var showPicUrl = document.getElementById("showPicUrl"); showPicUrl.innerText=imgFile.value; newPreview.style.width = "80px"; newPreview.style.height = "60px";}--></script> </head> <body> <p> 说明:以下针对的是互联网情况,如果您在本地作测试,比如输入的地址是:http://127.0.0.1/...,则可以看到全部预览。 </p> <hr /> <p> 如果您使用的是 IE6,则可以看到以下预览;如果您使用的是 IE7,则看不到以下预览。 </p> <div id="oldPreview"></div> <hr /> <p> 不论您使用的是 IE6 还是 IE7,均可以看到以下预览。 </p> <div id="newPreview"></div> <div id="showPicUrl"></div> <hr /> <p> 请选择一个图片进行预览: <input type="file" size="20" onchange="javascript:PreviewImg(this);" /> </p> </body></html>