js 獲取div高度並重新設置div高度與寬度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js 獲取div高度並重新設置div高度與寬度</title>
<script language="javascript教程">
var $=function(id) {
return document.getElementById(id);
}
function clickDiv()
{
$('testid').offsetWidth; // 20
$('testid').offsetHeight; //200
document.all.testid.style.width="1000px"; //js設置div寬度
document.all.testid.style.height="500px"; //設置div高度民主
//現在來重新設置一下testid的高度與寬度
//$('testid').offsetWidth = 300;
//$('testid').offsetHeight =300;
$('testid').style.className = 'idtest';
}
</script>
方法二
<script type="text/javascript">
alert(document.getElementById("testid").scrollHeight+'px');
</script>
方法三
<script type="text/javascript">
alert(document.getElementById("testid").clientHeight+'px');
</script>
<style type="text/css教程">
#testid{
height:50px;
width:200px;
background:#3300CC;
}
.idtest{
height:80px;
width:150px;
background:#FFFFFF;
}
</style>
</head>
<body>
<div id="testid">
</div>
<input type="button" value="點擊我" onclick="clickDiv();" />
</body>
</html>