asp.net旅行
<!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>
<title>jscript等比例压缩图片</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
<script type="text/javascript" >![](https://www.cnblogs.com/Images/dot.gif)
function ctlImg(img,w,h)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
var img_Width = w;
var img_Height = h;
var Owth = img.width;
var Ohth = img.height;
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(img.width>img_Width && img.height>img_Height)
{
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(Owth/img_Width > Ohth/img_Height)
{
img.width = img_Width;
img.height = parseInt(img_Width/Owth * Ohth);
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
else
{
img.height = img_Height;
img.width = parseInt(img_Height/Ohth * Owth);
}
return true;
}
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
if(Owth>img_Width)
{
img.width = img_Width;
img.height = parseInt(img_Width * (Ohth/Owth));
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
}else if(Ohth>img_Height)
{
img.height = img_Height;
img.width = parseInt(img_Height * (Owth/Ohth));
}
return true;
}
</script>
</head>
![](/Images/OutliningIndicators/None.gif)
<body>
<h1>jscript等比例压缩图片</h1>
<img onload="ctlImg(this,300,200);" src="http://www.tu888.cn/tesetuku/minghuabizhi/md61.jpg" />
<img onload="ctlImg(this,200,100);" src="http://www.tu888.cn/tesetuku/minghuabizhi/md61.jpg" />
<img onload="ctlImg(this,100,100);" src="http://www.tu888.cn/tesetuku/minghuabizhi/md61.jpg" />
<img onload="ctlImg(this,200,50);" src="http://www.tu888.cn/tesetuku/minghuabizhi/md61.jpg" />
</body>
</html>
![](/Images/OutliningIndicators/None.gif)