我正在尝试获取浏览器窗口的高度和宽度,因此它返回null,示例代码如下所示 我还使用了$ stack(“window”)。我在stackoverflow中找到的load(function())仍然返回null。
<html>
<head></head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></scipt>
<script>
$(document).ready(function(){
//$("#page").outerWidth($("window").width(),true);
// $("#page").outerHeight($("window").height(),true);
alert($("window").height() + " " + $("document").height() + " " +$("window").width());
});
</script>
</body>
</html>
答案 0 :(得分:4)
$("window")
应为$(window)
。
当您使用$("window")
时,您要求jQuery使用tagName&#34; window&#34;选择所有元素。 (并且没有)。当您使用$(window)
时,您实际上是在告诉jQuery包装window
对象。
而且,为了清楚起见,这也适用于$("document")
与$(document)
的变化。
答案 1 :(得分:0)
就是这样:
$(document).ready(
function () {
//$("#page").outerWidth($("window").width(),true);
// $("#page").outerHeight($("window").height(),true);
alert($(window).height() + " " + $(document).height() + " " + $(window).width());
}
);