国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

用document.documentElement取代document.body的原因分析

2024-05-06 14:12:51
字體:
來源:轉載
供稿:網友
IE6在頁面內容超出窗口大小時將寬度屬性scrollWidth、clientWidth、offsetWidth都解釋為內容實際寬度。
上次的測試說明了document.body屬性并不會給我們返回預期的結果,比如我們用document.body.clientHeight原本想取得“頁面可見區域高度”,可實際上返回的是“頁面實際內容高度”。
那我們怎么辦呢?難道加上了文檔DTD類型之后就再也不能取到“可見區域高度”和“內容實際寬度”等等屬性了嗎?
代碼如下:
<!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 runat="server">
<title>documentElement</title>
<style type="text/css">
body{margin:0;padding:0;font:12px/150% arial;}
</style>
<script type="text/javascript">
function a() {
var scrollTop;
var scrollLeft;
if (typeof window.pageYOffset != 'undefined') {
scrollTop = window.pageYOffset;
scrollLeft = window.pageXOffset;
}
else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
scrollTop = document.documentElement.scrollTop;
scrollLeft = document.documentElement.scrollLeft;
}
else if (typeof document.body != 'undefined') {
scrollTop = document.body.scrollTop;
scrollLeft = document.body.scrollLeft;
}
var scrollHeight = document.documentElement.scrollHeight;
var scrollWidth = document.documentElement.scrollWidth;
var clientWidth = document.documentElement.clientWidth;
var clientHeight = document.documentElement.clientHeight;
var offsetWidth = document.documentElement.offsetWidth;
var offsetHeight = document.documentElement.offsetHeight;
var screenTop = window.screenTop;
var screenBottom = window.screenBottom;
var screenLeft = window.screenLeft;
var sheight = window.screen.height;
var swidth = window.screen.width;
var availHeight = window.screen.availHeight;
var availWidth = window.screen.availWidth;
document.getElementById('scrollTop').value = scrollTop;
document.getElementById('scrollLeft').value = scrollLeft;
document.getElementById('scrollHeight').value = scrollHeight;
document.getElementById('scrollWidth').value = scrollWidth;
document.getElementById('clientWidth').value = clientWidth;
document.getElementById('clientHeight').value = clientHeight;
document.getElementById('offsetWidth').value = offsetWidth;
document.getElementById('offsetHeight').value = offsetHeight;
document.getElementById('screenTop').value = screenTop;
document.getElementById('screenBottom').value = screenBottom;
document.getElementById('screenLeft').value = screenLeft;
document.getElementById('sheight').value = sheight;
document.getElementById('swidth').value = swidth;
document.getElementById('availHeight').value = availHeight;
document.getElementById('availWidth').value = availWidth;
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 雷州市| 英山县| 沽源县| 若羌县| 新宾| 湘潭县| 利川市| 陈巴尔虎旗| 温州市| 文安县| 敦化市| 威信县| 屯留县| 图们市| 常熟市| 诏安县| 蚌埠市| 兰州市| 拉孜县| 鹿邑县| 静海县| 靖西县| 分宜县| 巴青县| 太原市| 丹东市| 扶绥县| 罗定市| 富源县| 中西区| 富川| 刚察县| 马公市| 军事| 盐池县| 德州市| 鄯善县| 宁都县| 沁阳市| 榆林市| 博野县|