用js取得DIV的top,left,width,height值

<script   type= "text/javascript "   language= "javascript ">
<!--
function   checkBrowser()
{
var   ClientInfo= " ";
ClientInfo   =   ClientInfo   +   "userAgent   :   "+window.navigator.userAgent+ " <br> ";
ClientInfo   =   ClientInfo   +   "appName   :   "+window.navigator.appName+ " <br> ";
ClientInfo   =   ClientInfo   +   "appVersion   :   "+window.navigator.appVersion+ " <br> ";
ClientInfo   =   ClientInfo   +   "appMinorVersion   :   "+window.navigator.appMinorVersion+ " <br> ";
ClientInfo   =   ClientInfo   +   "appCodeName   :   "+window.navigator.appCodeName+ " <br> ";
ClientInfo   =   ClientInfo   +   "platform   :   "+window.navigator.platform+ " <br> ";
ClientInfo   =   ClientInfo   +   "language   :   "+window.navigator.language+ " <br> ";
ClientInfo   =   ClientInfo   +   "userLanguage   :   "+window.navigator.userLanguage+ " <br> ";
ClientInfo   =   ClientInfo   +   "cpuClass   :   "+window.navigator.cpuClass+ " <br> ";
ClientInfo   =   ClientInfo   +   "onLine   :   "+window.navigator.onLine+ " <br> ";
//ClientInfo   =   ClientInfo   +   "javaEnabled   :   "+window.navigator.javaEnabled+ " <br> ";
ClientInfo   =   ClientInfo   +   "mimeTypes   :   "+window.navigator.mimeTypes+ " <br> ";
ClientInfo   =   ClientInfo   +   "plugins   :   "+window.navigator.plugins+ " <br> ";
ClientInfo   =   ClientInfo   +   "cookieEnabled   :   "+window.navigator.cookieEnabled+ " <hr> ";

ClientInfo   =   ClientInfo   +   "screen.colorDepth   :   "+window.screen.colorDepth+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "screen.width   :   "+window.screen.width+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "screen.height   :   "+window.screen.height+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "screenTop   :   "+window.screenTop+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "screenLeft   :   "+window.screenLeft+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "screen.availWidth   :   "+window.screen.availWidth+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "screen.availHeight   :   "+window.screen.availHeight+ "   px <hr> ";

ClientInfo   =   ClientInfo   +   "body.clientWidth   :   "+document.body.clientWidth+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.clientHeight   :   "+document.body.clientHeight+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.clientTop   :   "+document.body.clientTop+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.clientLeft   :   "+document.body.clientLeft+ "   px <hr> ";

ClientInfo   =   ClientInfo   +   "body.offsetWidth   :   "+document.body.offsetWidth+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.offsetHeight   :   "+document.body.offsetHeight+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.offsetTop   :   "+document.body.offsetTop+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.offsetLeft   :   "+document.body.offsetLeft+ "   px <hr> ";

ClientInfo   =   ClientInfo   +   "body.scrollWidth   :   "+document.body.scrollWidth+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.scrollHeight   :   "+document.body.scrollHeight+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.scrollTop   :   "+document.body.scrollTop+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "body.scrollLeft   :   "+document.body.scrollLeft+ "   px <hr> ";

ClientInfo   =   ClientInfo   +   "div.clientWidth   :   "+document.getElementById( "Desktop ").clientWidth+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.clientHeight   :   "+document.getElementById( "Desktop ").clientHeight+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.clientTop   :   "+document.getElementById( "Desktop ").clientTop+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.clientLeft   :   "+document.getElementById( "Desktop ").clientLeft+ "   px <hr> ";

ClientInfo   =   ClientInfo   +   "div.offsetWidth   :   "+document.getElementById( "Desktop ").offsetWidth+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.offsetHeight   :   "+document.getElementById( "Desktop ").offsetHeight+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.offsetTop   :   "+document.getElementById( "Desktop ").offsetTop+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.offsetLeft   :   "+document.getElementById( "Desktop ").offsetLeft+ "   px <hr> ";

ClientInfo   =   ClientInfo   +   "div.scrollWidth   :   "+document.getElementById( "Desktop ").scrollWidth+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.scrollHeight   :   "+document.getElementById( "Desktop ").scrollHeight+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.scrollTop   :   "+document.getElementById( "Desktop ").scrollTop+ "   px <br> ";
ClientInfo   =   ClientInfo   +   "div.scrollLeft   :   "+document.getElementById( "Desktop ").scrollLeft+ "   px <hr> ";
document.getElementById( "Desktop ").innerHTML   =   ClientInfo;
}
//-->
</script>

 

例如:有左右两栏,右边为内容区域,所以高度height:auto,左侧想设置背景色,跟右侧高度一样,这是在js里把右侧的高度值赋值给左侧的高度。

           可以这样写:document.getElementById("Ga10").style.height=document.getElementById("Ga11").offsetHeight+"px";

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值