用户上传的图片可能过大,可以用此限定。
Html:
Js:
Html:
<div style="width:100px;height:100px;border:1px solid #F1F1EA;text-align:center;vertical-align:middle;">
<a href="<%=rdetail_url%>"><IMG SRC="<%=rmag_url %>" onload="autoImageSize(this,100,100)" border="0"></a>
</div>
Js:
function autoImageSize(imgObj,setWidth,setHeight){
var imgWidth = imgObj.width;
var imgHeight = imgObj.height;
//alert(imgWidth + '===' + imgHeight);
if(imgWidth >= setWidth && imgHeight >= setHeight){
if(imgWidth > imgHeight){
imgObj.width = setWidth;
}else{
imgObj.height = setHeight;
}
}
if(imgWidth <= setWidth && imgHeight <= setHeight){
imgObj.width = imgWidth;
imgObj.height = imgHeight;
}
if(imgWidth >= setWidth && imgHeight <= setHeight){
imgObj.width = setWidth;
}
if(imgWidth <= setWidth && imgHeight >= setHeight){
imgObj.height = setHeight;
}
}