您的位置:首页 > Web前端 > JavaScript

JS实现兼容IE6、IE7、IE8的图片上传前预览效果

2013-08-19 11:33 1031 查看
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>兼容IE6、IE7、IE8的图片上传前预览效果</title>

<meta http-equiv="content-type" content="text/html;charset=gb2312">

<!--把下面代码加到<head>与</head>之间-->

<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>

<!--把下面代码加到<body>与</body>之间-->

<div id="newPreview"></div>

<div id="showPicUrl"></div>

<hr><br>

请选择图片:<input type="file" name="file" onchange="javascript:PreviewImg(this);">

</body>

</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: