如何在<img >里面写js代码设置图片的大小?
<img>里面写js代码,不知道用什么事件好?当图片长超过200时设置图片长为200怎么写?
------解决方案-------------------- <script language= "JavaScript " type= "text/javascript ">
<!--
function DrawImage(ImgD){
var image=new Image();
var intWidth = 200;
image.src=ImgD.src;
if(image.width> intWidth)
{
ImgD.width=intWidth;
ImgD.height=(image.height*intWidth)/image.width;
}
else
{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
//-->
</script>
</head>
<body>
<Img id= "sImg " src= "gong.gif " onload= "javascript:DrawImage(this); ">
</body>