clientWidth、offsetWidth、clientHeight、offsetHeight的测试比较
生活随笔
收集整理的這篇文章主要介紹了
clientWidth、offsetWidth、clientHeight、offsetHeight的测试比较
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border
<html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]" lang="gb2312">
<head>
<head>
<title> 代碼實例:關(guān)于clientWidth、offsetWidth、clientHeight、offsetHeight的測試比較 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content="楓巖,CnLei.y.l@gmail.com">
<meta name="copyright" content="[url=http://www.cnlei.com]http://www.cnlei.com[/url]" />
<meta name="description" content="關(guān)于clientWidth、offsetWidth、clientHeight、offsetHeight的測試比較" />
<style type="text/css" media="all">
body {font-size:14px;}
a,a:visited {color:#00f;}
#Div_CnLei {
width:300px;
height:200px;
padding:10px;
border:10px solid #ccc;
background:#eee;
font-size:12px;
}
#Div_CnLei p {margin:0;padding:10px;background:#fff;}
</style>
<script type="text/javascript">
function Obj(s){
return document.getElementById(s)?document.getElementById(s):s;
}
function GetClientWidth(o){
return Obj(o).clientWidth;
}
function GetClientHeight(o){
return Obj(o).clientHeight;
}
function GetOffsetWidth(o){
return Obj(o).offsetWidth;
}
function GetOffsetHeight(o){
return Obj(o).offsetHeight;
}
</script>
</head>
<body>
<p>點擊下面的鏈接:</p>
<div id="Div_CnLei">
<p><a href="javascript:alert(GetClientWidth('Div_CnLei'));">GetClientWidth();</a> <a href="javascript:alert(GetClientHeight('Div_CnLei'));">GetClientHeight();</a></p>
<p><a href="javascript:alert(GetOffsetWidth('Div_CnLei'));">GetOffsetWidth();</a> <a href="javascript:alert(GetOffsetHeight('Div_CnLei'));">GetOffsetHeight();</a></p>
</div>
<div id="Description">
<p><strong>IE6.0、FF1.06+:</strong><br />
clientWidth = width + padding = 300+10×2 = 320<br />
clientHeight = height + padding = 200+10×2 = 220<br />
offsetWidth = width + padding + border = 300+10×2+10×2= 340<br />
offsetHeight = height + padding + border = 200+10×2+10×2 = 240</p>
</div>
</body>
</html>
?
轉(zhuǎn)載于:https://www.cnblogs.com/reommmm/archive/2010/04/19/1715267.html
總結(jié)
以上是生活随笔為你收集整理的clientWidth、offsetWidth、clientHeight、offsetHeight的测试比较的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “LM/w3svc/1/root /**
- 下一篇: 【转】细数中国十大名校的IT牛人