王老师在不在?帮我看下,怎么固定宽度?
<script language= "javascript " type= "text/javascript ">
var flag=false;
function DrawImage(ImgD,intHeight)
{
var image=new Image();
image.src=ImgD.src;
if(image.width> 0 && image.height> 0)
{
if(image.height > intHeight)
{
ImgD.width = image.width /image.height * intHeight;
ImgD.height = intHeight;
}
}
}
</script>
<img src= "showing.asp?id=2 " onload= "javascript:DrawImage(this,200); ">
上面是固定图片高度的代码,现在我想固定宽度?应该怎么改?
------解决方案-------------------- <script language= "javascript " type= "text/javascript ">
var flag=false;
function DrawImage(ImgD,intWidth)
{
var image=new Image();
image.src=ImgD.src;
if(image.width> 0 && image.height> 0)
{
if(image.width > intWidth)
{
ImgD.height = image.height /image.width * intWidth;
ImgD.width = intWidth;
}
}
}
</script>
------解决方案--------------------晕死,固定高度都会了,固定宽度不是一个道理么?
<script language= "javascript " type= "text/javascript ">
function DrawImage(ImgD,intWidth)
{
var image=new Image();
image.src=ImgD.src;
if(image.width> 0 && image.height> 0)
{
if(image.width > intWidth)
{
ImgD.height = image.height/image.width * intWidth;
ImgD.width = intWidth;
}
}
}
</script>