
jquery 如何获得窗口的宽和高
展开全部
提供你一个函数,获取浏览器显示部分的高度,兼容所有主流浏览器
<script>
function getWindowSize() {
var client = {
x:0,
y:0
};
if(typeof document.compatMode != 'undefined' && document.compatMode == 'CSS1Compat') {
client.x = document.documentElement.clientWidth;
client.y = document.documentElement.clientHeight;
} else if(typeof document.body != 'undefined' && (document.body.scrollLeft || document.body.scrollTop)) {
client.x = document.body.clientWidth;
client.y = document.body.clientHeight;
}
return client;
}
function getsize(){
var size = getWindowSize();
document.getElementById("width").value = size.x;
document.getElementById("height").value = size.y;
}
</script>
<body onresize="getsize()">
width:<input type="text" id="width" /><br />
height:<input type="text" id="height" />
</body>
<script>
function getWindowSize() {
var client = {
x:0,
y:0
};
if(typeof document.compatMode != 'undefined' && document.compatMode == 'CSS1Compat') {
client.x = document.documentElement.clientWidth;
client.y = document.documentElement.clientHeight;
} else if(typeof document.body != 'undefined' && (document.body.scrollLeft || document.body.scrollTop)) {
client.x = document.body.clientWidth;
client.y = document.body.clientHeight;
}
return client;
}
function getsize(){
var size = getWindowSize();
document.getElementById("width").value = size.x;
document.getElementById("height").value = size.y;
}
</script>
<body onresize="getsize()">
width:<input type="text" id="width" /><br />
height:<input type="text" id="height" />
</body>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$("#id").offset().top 获取控件在整个页面的位置
$("#id").height() 获取控件的高度
$("#id").height() 获取控件的高度
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$(window).width()
$(window).height()
$(window).height()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询