老漂 不要有和人斗的心,你要赢的是你自己!

没有图片的显示默认图片,限制图片尺寸 代码

1.找不到图片,则显示默认图

<td><IMG src="../images/skin/<%=BoardStyle%>/preview.gif" onerror="javascript:this.src='../images/skin/preview.gif'" width="400" height="300"></td>

 

2.固定宽度

<img src= "image/index.jpg " onload= "javascript:if(this.width> 500) this.width=500; ">

3.限制图片长宽

function changeImg(obj,width,height) {  if ( obj.width > width || obj.height > height ) {    var scale;    var scale1 = obj.width / width;    var scale2 = obj.height / height;    if(scale1 > scale2){        scale = scale1;    }else{        scale = scale2;    }    obj.width = obj.width / scale;    obj.height = obj.height / scale;  }}---------------使用例子<img src="xx.jpg" onload="changeImg(this,180,180)">
2011年9月22日 | 发布:老漂 | 分类:网站|站长 | 评论:0

发表留言: