上传图片预览

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>图片上传</title>
<script>
function viewmypic(imgfile) {
if (imgfile.value){
var oImg = new Image();
oImg.src = imgfile.value;
var ow = oImg.width;
var oh = oImg.height;
var ow2 = ow, oh2 = oh;// 得到宽高
try {
if (ow > oh) {
if (ow > 200) {
ow2 = 200;
oh2 = "auto";
}
} else {
if (oh > 200) {
oh2 = 200;
ow2 = "auto";
}
}
var getimg = "<a href=\""
+ oImg.src
+ "\" οnclick=\"window.open(this.href,'','width=500,height=400,top='+(window.screen.height-500)/2+',left='+(window.screen.width-500)/2+',resizable=yes ');return false;\" target=\"_blank\">"
+ "<img border=\"0\" id=\"uploadimg\" src=\"" + oImg.src
+ "\" style=\"width:" + ow2 + ";height:" + oh2 + ";\">"
+ "</a>";
document.getElementById("showPic").innerHTML = getimg;
document.getElementById("showPic").style.display='';
} catch (ex) {
alert(ex.toString());
}
}
}
</script>
</head>
<body>
<center>
<form >
<input name="imgfile" type="file" id="imgfile" size="40" οnchange="viewmypic(this);" />
</form>
<img name="showimg" id="showimg" src="" style="display:none;" alt="预览图片" />
<br />
<div id='showPic' style="display:none">
</div>
</center>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值