图片上传预览firefox和ie

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">

	<script type="text/javascript">

function PreviewImg(imgFile,idname) {
  
	if (checkPic(idname) == true) {

		if (navigator.userAgent.indexOf("MSIE")>0) {
			var newPreview = document.getElementById("newPreview");
			newPreview.removeChild(document.getElementById("imgDiv"));
			var imgDiv = document.createElement("div");
			imgDiv.setAttribute("id", "imgDiv");
			document.body.appendChild(imgDiv);
			imgDiv.style.width = "150px";
			imgDiv.style.height = "150px";
			imgDiv.style.algin = "center";
			imgDiv.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod = scale)";
			imgDiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgFile.value;
			document.getElementById("imageUplaod").style.display = "none";
		}

		if (isFirefox=navigator.userAgent.indexOf("Firefox")>0) {
			document.getElementById("imageUplaod").src = window.URL
					.createObjectURL(imgFile.files[0]); //火狐预览效果

		}

		newPreview.appendChild(imgDiv);

		newPreview.style.width = "150px";
		newPreview.style.height = "150px";
	}
}

function checkPic(idname) {
     alert(idname);
	var picPath = document.getElementById(""+idname+"").value;
	var type = picPath.substring(picPath.lastIndexOf(".") + 1, picPath.length)
			.toLowerCase();
	if (type == "jpg" || type == "bmp" || type == "gif" || type == "png") {

		return true;
	} else {
		alert("请上传正确的图片格式");
		return false;
	}
}
</script>
	<body>
		<p>
			图片上传:
			<input type="file" size="20" οnchange="PreviewImg(this,'picPath');"
				id="picPath" />
		</p>
		宽度:
		<input type="text" size="13" id="imageWidth" />
		高度:
		<input type="text" size="13" id="imageHigh" />
		<br />
		<p>
			<div id="newPreview" style="margin: 0px auto;">
				<div id="imgDiv" style="display: none;"></div>
			</div>
			<img src="" width="150px" height="150px" id="imageUplaod"/>
			<br />
	</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值