Jquery window.height()不工作?试图得到窗口的宽度
我想对窗户的高度和宽度做一个调整,但这个高度不起作用。这是我迄今为止尝试过的代码Jquery window.height()不工作?试图得到窗口的宽度,jquery,Jquery,我想对窗户的高度和宽度做一个调整,但这个高度不起作用。这是我迄今为止尝试过的代码 <style> .box { display:block; background:#0FC;} </style> <body> <div class="box"> anc </div> <script> var height= $(window).height(); var width=$(window).width();
<style>
.box { display:block; background:#0FC;}
</style>
<body>
<div class="box">
anc
</div>
<script>
var height= $(window).height();
var width=$(window).width();
$(".box").width() = width;
$(".box").height() = height;
</script>
我做错什么了吗?如果是这样的话,请您给我看一下正确的代码!
非常感谢应该是这样的
$(function(){
var height= $(window).height();
var width=$(window).width();
$(".box").height(height);
$(".box").width(width);
});
应该是这样的
$(function(){
var height= $(window).height();
var width=$(window).width();
$(".box").height(height);
$(".box").width(width);
});
首先,您缺少document.ready,并且在定义高度和宽度时使用了错误的语句
<script>
$(function(){
var height= $(window).height();
var width=$(window).width();
$(".box").width(width);
$(".box").height(height);
});
</script>
要设置宽度,您需要将其作为参数传递。首先,您缺少document.ready,并且在定义高度和宽度时使用了错误的语句
<script>
$(function(){
var height= $(window).height();
var width=$(window).width();
$(".box").width(width);
$(".box").height(height);
});
</script>
要设置宽度,需要将其作为参数传递。不需要jquery:
window.innerHeight
window.innerWidth
document.body.clientWidth
document.body.clientHeight
文档比您通过文档查看的窗口大得多您不需要jquery:
window.innerHeight
window.innerWidth
document.body.clientWidth
document.body.clientHeight
var height= $(window).height();
var width=$(window).width();
$(".box").width(width);
$(".box").height(height);
文档比您通过文档查看的窗口大得多
var height= $(window).height();
var width=$(window).width();
$(".box").width(width);
$(".box").height(height);
演示:-
演示:-$.box.widthwidth$.box.widthwidth