<script type="text/JavaScript">
//<![CDATA[
window.onload=function(){
fResizeImg(500, 500, 'cntall');
//fResizeImg(500, 500);
}
/*------------------------------------------------------*\
* Subject: 使用 JavaScript 函数 完美控制页面图片显示大小 By shawl.qiu
* 使用:
* --------------------------------------
* 1. JavaScript 脚本块
* window.onload=function(){
* fResizeImg(500, 500, 'img');
* //fResizeImg(500, 500);
* }
*
* 2. HTML body 标签
* <body onload="fResizeImg(500, 500, 'textMain');" >
* --------------------------------------
* 注: 必须在页面加载完毕后使用本函数(这是基本的客户端应用概念)
\*-------------------------------------------------------*/
//---------------------------------begin function fResizeImg();
function fResizeImg(w, h, id){
var img='';
var obj;
if(id==undefined)obj=document.images;
else obj=document.getElementById(id).getElementsByTagName('img');
for(var i=0; i<obj.length; i++){
img=obj[i];
if(img.width>w&&(img.height<img.width)){
img.height=img.height-(img.height/(img.width/(img.width-w)))
img.width=w;
}else if(img.height>h&&(img.height>img.width)){
img.width=img.width-(img.width/(img.height/(img.height-h)))
img.height=h;
}
img.onclick=function(){
try{ imgPopup.close();} catch(e){}
imgPopup=open('#', 'imgurl', '')
imgPopup.document.write('<img src="'+this.src+'"/>');
imgPopup.document.close();
imgPopup.focus();
}
} // shawl.qiu script
}
//---------------------------------end function fResizeImg();
//]]>

BK网络学院主要内容:平面设计教程,网站开发在线教程,网页制作教程,服务器教程,网络编程,数据库教程等。