<html>
<head>
<script>
function allProps(obj){
// 用來保存所有的屬性名稱和值
var props = "";
// 開始遍歷
if(typeof obj== "string"){
props =obj;
}else{
if(obj!=null&& (typeof obj =="object")){
for(var p in obj){
// 方法
if(typeof(obj[p])=="function"){
}else{
// p 為屬性名稱,obj[p]為對(duì)應(yīng)屬性的值
props+= p + "=" + obj[p] + "\r\n";
}
}
}
}
// 最后顯示所有的屬性
alert(props);
}
//js控制圖片的顯示最寬和最高值
function drawImage(ImgId,maxwidth,maxheight){
//本程序?qū)D像控制在寬為maxwidth且高為maxheight的框內(nèi)
//ImgD是圖像ID,maxwidth、maxheight是圖像最大顯示寬度和高度
var ImgD=document.getElementById(ImgId);
allProps(ImgD);
var image=new Image();
image.src=ImgD.src;
var imgwidth=image.width;
var imgheight=image.height;
if(imgwidth>0 && imgheight>0 && maxwidth>0 && maxheight>0){
if(imgwidth>maxwidth || imgheight>maxheight){
if(imgwidth/imgheight>= maxwidth/maxheight){
ImgD.width=maxwidth;
ImgD.height=(imgheight*maxwidth)/imgwidth;
}
else{
ImgD.height=maxheight;
ImgD.width=(imgwidth*maxheight)/imgheight;
}
}else{
ImgD.width=imgwidth;
ImgD.height=imgheight;
}
}
}
</script>
</head>
<body>
<img id="thisimage" src="http://d5.sina.com.cn/201101/31/283911_750-450.jpg">
<script>
drawImage('thisimage',80,80);
</script>
</body>
</html>