编写相应程序代码即可。
代码如下:
<script>
function getInfo()
{
var s = ""
s += " 网页可见区域宽:"+ document.body.clientWidth
s += " 网页可见区域高:"+ document.body.clientHeight
s += " 网页可见区域宽:"+ document.body.offsetWidth + " (包括边线和滚动条的宽)"
s += " 网页可见区域高:"+ document.body.offsetHeight + " (包括边线的宽)"
s += " 网页正文全文宽:"+ document.body.scrollWidth
s += " 网页正文全文高:"+ document.body.scrollHeight
s += " 网页被卷去的高(ff):"+ document.body.scrollTop
s += " 网页被卷去的高(ie):"+ document.documentElement.scrollTop
s += " 网页被卷去的左:"+ document.body.scrollLeft
s += " 网页正文部分上:"+ window.screenTop
s += " 网页正文部分左:"+ window.screenLeft
s += " 屏幕分辨率的高:"+ window.screen.height s += " 屏幕分辨率的宽:"+ window.screen.width
s += " 屏幕可用工作区高度:"+ window.screen.availHeight
s += " 屏幕可用工作区宽度:"+ window.screen.availWidth
s += " 你的屏幕设置是 "+ window.screen.colorDepth +" 位彩色"
s += " 你的屏幕设置 "+ window.screen.deviceXDPI +" 像素/英寸"
//alert (s)
}
getInfo()
</script>
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<style>
#div {
width: 100px
height: 50px
border: 1px solid red
color: green
text-align: center
}
input {
width: 250px
}
</style>
<script>
function test() {
var a = document.getElementById('a')
var b = document.getElementById('b')
var div = document.getElementById('div')
div.style.width = a.value + 'px'
div.style.height = b.value + 'px'
}
</script>
</head>
<body>
<div>宽度(默认100px):<input type="text" id="a" placeholder="输入想要的宽度,点击测试看效果" /></div>
<div>高度(默认50px):<input type="text" id="b" placeholder="输入想要的高度,点击测试看效果" /></div>
<div><button onclick="test()">点击测试</button></div>
<div id="div">来改变我</div>
</body>
</html>
js改变DIV高度,首先获取到这个DIV元素,然后用style.height改变其高度即可。相关实例代码如下:
<p id="demo" onclick="Gheight()">内容</p>
<script>
function Gheight(){
var x=document.getElementById("demo")
x.offsetHeight==100?x.style.height="200px":x.style.height="100px"
}
</script>