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>
- 上一篇:文本框 css 关闭 输入法
- 下一篇:JavaScript 取当前屏幕大小