日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

clientWidth、offsetWidth、clientHeight、offsetHeight的测试比较

發布時間:2025/3/20 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 clientWidth、offsetWidth、clientHeight、offsetHeight的测试比较 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border

代碼 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
<html xmlns="[url=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/url]" lang="gb2312">
<head>
<head>
<title> 代碼實例:關于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="關于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>

?

轉載于:https://www.cnblogs.com/reommmm/archive/2010/04/19/1715267.html

總結

以上是生活随笔為你收集整理的clientWidth、offsetWidth、clientHeight、offsetHeight的测试比较的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。