function imgSize(ImgD, iwidth, iheight) {
var image = new Image();
image.src = ImgD.src;
if (image.width > 0 && image.height > 0) {
if (image.width / image.height >= iwidth / iheight) {
if (image.width > iwidth) {
ImgD.width = iwidth;
ImgD.height = (image.height * iwidth) / image.width;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
} else {
if (image.height > iheight) {
ImgD.height = iheight;
ImgD.width = (image.width * iheight) / image.height;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
}
}
}
function changeAllImage(iwidth, iheight){
var imgs = document.images;
for (j=0; j<imgs.length; j=j+1){
var img = document.images[j];
imgSize(img, iwidth, iheight);
}
}
=======================
引用:
<img src='001.jpg' onload='imgSize(this, 143, 200)'/>
以上操作會產生 Undefined attribute name (onload). 警告
可以:
<body onload=' changeAllImage(143, 200)' >
……
<image src='001.jpg' />
……
</body>