发布网友 发布时间:2022-04-24 17:48
共2个回答
热心网友 时间:2022-05-11 21:55
//js部分
$(document).ready(function() {
$("#button").click(function() {
alert("高:"+$(document).height()+" 宽:"+$(document).width());
});
});
<!-- html 部分 -->
<button id="button">点击显示</button>
你真确定不好使?检查一下jquery路径吧。
追答好吧,其实是这样的,$(document)获得的是页面文档,我忽略了整个文档可能超过窗口的大小,的纯粹获得窗口大小你需要把$(document)换成$(window)。
热心网友 时间:2022-05-11 23:13
有文档声明的测试代码:
Html代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>测试1</title>
<script type="text/javascript">
function show(){
var s = "";
s += "网页可见区域宽度:"+document.body.clientWidth;
s += "\n网页可见区域高度:"+document.body.clientHeight;
s += "\n网页可见区域宽度(包括边线):"+document.body.offsetWidth;
s += "\n网页可见区域高度(包括边线):"+document.body.offsetHeight;
s += "\n网页正文宽度:"+document.body.scrollWidth;
s += "\n网页正文高度:"+document.body.scrollHeight;
s += "\n屏幕可用工作区域宽度:"+window.screen.availWidth;
s += "\n屏幕可用工作区域高度:"+window.screen.availHeight;
s += "\n屏幕分辨率宽度:"+window.screen.width;
s += "\n屏幕分辨率高度:"+window.screen.height;
alert(s);
}
</script>
</head>
<body style="margin:0;border:0">
<div style="width:2000px;height:90px;margin:0">
<a onclick="show()" href="#">点击</a>
</div>
</body>
</html>
无文档声明的测试代码
Html代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>测试2</title>
<script type="text/javascript">
function show(){
var s = "";
s += "网页可见区域宽度:"+document.body.clientWidth;
s += "\n网页可见区域高度:"+document.body.clientHeight;
s += "\n网页可见区域宽度(包括边线):"+document.body.offsetWidth;
s += "\n网页可见区域高度(包括边线):"+document.body.offsetHeight;
s += "\n网页正文宽度:"+document.body.scrollWidth;
s += "\n网页正文高度:"+document.body.scrollHeight;
s += "\n屏幕可用工作区域宽度:"+window.screen.availWidth;
s += "\n屏幕可用工作区域高度:"+window.screen.availHeight;
s += "\n屏幕分辨率宽度:"+window.screen.width;
s += "\n屏幕分辨率高度:"+window.screen.height;
alert(s);
}
</script>
</head>
<body style="margin:0;border:0">
<div style="width:2000px;height:90px;margin:0">
<a onClick="show()" href="#">点击</a>
</div>
</body>
</html>