JS实现上传本地图片前预览图片,兼容IE6和IE7,有很多这样的代码,但不知道为什么会在IE7下失效,于是将以前的修正了一下,这下可以完全兼容IE6和IE7,实用性大大增强,也方便了用户在上传图片前确认自己将要上传的图片是否正确。
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>JS上传前预览图片</title>
- <script type="text/javascript" language="javascript">
- <!--
- function PreviewImg(imgFile){
- 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>兼容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>
阅读(2045) | 评论(0) | 转发(0) |