专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
JSCSS
当前位置:首页 > 技术文档 > JSCSS >  > 
JavaScript 动态得到html 元素显示大小值

JavaScript 动态得到html 元素显示大小值


document.getElementById('d1').clientWidth;


经测试IE 8 FF 都可以显示出来。


以下是测试代码


<head>


<meta http-equiv="Content-Type" content="text/html; charset=gbk" />


<title>无标题文档</title>


</head>


<style>


.d1 { overflow:hidden; background-color:#09F;


    }


.d2{


    width:400px; height:250px; background-color:#CC3;


    }


</style>


<script language="javascript">


function test()


{


    alert(document.getElementById('d1').clientWidth)


    window.screen.width


      


}


</script>


<body>


<div id="d1" class="d1">


<div class="d2"></div>


</div>


<input type="button" value="tttt" onclick="test()" />



</body>


</html>