用法:將以下代碼保存爲HTML格式的頁面即可。
實現的功能:
當頁面裏內容的高度沒有讓頁面出現滾動條時,頁面當前頁面的最底部顯示。
當出現滾動條後,DIV層會自動向下跟隨,在頁面的最底部顯示。
更改TABLE的高度就可以看到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.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>JS獲取網頁高度及屏幕分辨率高度讓DIV層始終在頁面最底部</title>
</head>
<body leftmargin="0" topmargin="0">
<table width="100%" height="405" bgcolor="#eeeeee">
<tr>
<td>
aaa
</td>
</tr>
</table>
<div id="t1" style="position:absolute;border:double;">
aaaaaaa
</div>
<script language="javascript">
//document.all.t1.style.top = document.body.clientHeight;
var h1 = window.screen.availHeight-165;
if (document.body.clientHeight<h1)
document.all.t1.style.top = window.screen.availHeight-165;
document.write ("當前窗口寬:"+document.body.offsetWidth+"; 高:"+document.body.clientHeight+"aaaa"+(window.screen.availHeight));
</script>
</body>
</html>